contos 编译运行简单的 c++
1、准备工作:安装gcc编译环境
yum install gcc-c++
2、创建cpp文件
[root@localhost demo]# touch test.cpp
[root@localhost demo]# vim test.cpp
#include <iostream> using namespace std; int main(){ cout<<"hello world"; }
3、编译运行文件 (注:书写格式)
[root@localhost demo]# g++ -o test.cpp test g++: error: test: No such file or directory g++: fatal error: no input files
[root@localhost demo]# vim test.cpp [root@localhost demo]# g++ test.cpp -o test [root@localhost demo]# ls test test.cpp [root@localhost demo]# ./test hello world