Compile and run C++ program under linux system

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 vimthe command to open the editor to write code,
insert image description here
first write the simplest output program

#include<iostream>
using namespace std;
int main()
{
    
    
        cout<<"hello world!"<<endl;
        return 0;
}

EscPress to exit edit mode when done , enter to :wqsave and exit. You can see that the hello.cppc file exists in the directory.
insert image description here

generate executable

Excuting an order

g++ -o hello hello.cpp

That is, hello.cpp is compiled into the hello executable file.
insert image description here

execute program

/hello

insert image description here

Guess you like

Origin blog.csdn.net/qq_44878985/article/details/129890941