安装编译环境
sudo apt-get install build-essential
打开vim
输入:
#include <iostream> //这里不要写成<iostream.h>不然会冒出一个warning的
using namespace std;
int main() //‘::main’ 必须返回 ‘int’ 如果你想写void main的话会报error的
{
cout << "Hello world!" << endl;
return 0;
}
保存为 hellolinux.cc C++的文件格式 .cpp好像也可以
然后 (C++)调用G++ 不是(C)GCC
命令如下:
g++ hellolinux.cc -o hello //-o 参数是代表输出
运行:
./hello
就会输出:
Hello world!
using namespace std;
int main() //‘::main’ 必须返回 ‘int’ 如果你想写void main的话会报error的
{
cout << "Hello world!" << endl;
return 0;
}
保存为 hellolinux.cc C++的文件格式 .cpp好像也可以
然后 (C++)调用G++ 不是(C)GCC
命令如下:
g++ hellolinux.cc -o hello //-o 参数是代表输出
运行:
./hello
就会输出:
Hello world!