ubuntu下C++程序的编译和运行

1、vi  hello.cpp

2.输入i进入插入模式,输入以下代码
#include <iostream> using namespace std; int main(int argc, char *argv[]){ std::cout<<"Hello World!"<<std::endl; return (0); } </iostream>

3、按下ESC,退出插入模式

4、输入:

5、输入wq       ---保存退出

6、打开终端输入g++ hello.cpp  进行编译

7、运行

     在终端里输入./a.out

注:1、g++编译c++语言,gcc编译c语言

        2、如果在同一个文件夹编译几个c++程序,生成的a.out可执行文件,会被覆盖。

             此时,要用到这个命来将可执行文件重命名。

            g++   -o   my1  hello.cpp

            执行./.my1(在终端输入)

猜你喜欢

转载自blog.csdn.net/qq_20768851/article/details/78328462