我使用的是Vi+GCC
下面在Linux下编写一个小的c++程序,步骤:
1.在Terminal下执行:Vim test.cpp
在test.cpp中编写代码:
#include<iostream>
int main()
{
std::cout<<"Enter two numbers:"<<std::endl;
int v1,v2;
std::cin>>v1>>v2;
std::cout<<"The sum of "<<v1<<" and "<<v2
<<" is "<<v1+v2<<std::endl;
return 0;
}
编辑完毕退出:wq
执行 g++ test.cpp -o test编译cpp文件生成test输出文件
执行./test就可以看到程序的输出结果了.
Enter two numbers:
12 5
The sum of 12 and 5 is 17
一个简单的c++程序完成了。