premise
First of all, there must be a C++ compilation environment under the linux system. can use
which gcc
which g++
Check whether the GNU compiler is installed in the linux system.
Write code
Use vim
the command to open the editor to write code,
first write the simplest output program
#include<iostream>
using namespace std;
int main()
{
cout<<"hello world!"<<endl;
return 0;
}
Esc
Press to exit edit mode when done , enter to :wq
save and exit. You can see that the hello.cppc file exists in the directory.
generate executable
Excuting an order
g++ -o hello hello.cpp
That is, hello.cpp is compiled into the hello executable file.
execute program
。/hello