环境搭建
使用CentOS 7系统的linux虚拟机,安装gcc编译器
yum -y install gcc
安装g++编译器命令:注意是gcc-c++,不能是g++
yum -y install gcc-c++
安装成功
[root@localhost bin]# which gcc
/usr/bin/gcc
[root@localhost bin]# which c++
/usr/bin/c++
编写.c或.cpp文件
[root@localhost clearn]# vim hello.c
#include<stdio.h>
int main(){
printf("Hello,world");
}
.cpp
[root@localhost clearn]# vim hello.cpp
#include<iostream>
using namespace std;
int main(){
cout<<"Hello,world!";
}
编译文件
[root@localhost clearn]# gcc hello.c -o hello1
[root@localhost clearn]# ./hello1
Hello,world[root@localhost clearn]#
[root@localhost clearn]# g++ hello.cpp -o hello2
[root@localhost clearn]# ./hello2
Hello,world![root@localhost clearn]#