linux系统下编译运行C++程序

前提

首先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

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_44878985/article/details/129890941