前提
首先linux系统下要有C++编译环境。可以使用
which gcc
which g++
查看linux系统下是否安装GNU编译器。
编写代码
使用vim
命令打开编辑器编写代码
先写一个最简单的输出程序
#include<iostream>
using namespace std;
int main()
{
cout<<"hello world!"<<endl;
return 0;
}
完成后按下Esc
退出编辑模式,输入:wq
保存并退出。可以看到目录下存在hello.cppc文件。
生成可执行文件
执行命令
g++ -o hello hello.cpp
即把hello.cpp编译成hello可执行文件。
执行程序
。/hello