
ubuntu编译cpp的示例:
1.编写C++文件,保存为“test1.cpp”。
//-------------ubuntu上.cpp文件编译与运行
#include
int main()
{
using namespace std;
const int ArSize = 20;
char name[ArSize];
char dessert[ArSize];
cout < "enter="" your="">
cin.getline(name, ArSize);
cout < "enter="" your="" favorite="">
cin.getline(dessert, ArSize);
cout < "i="" have="" some="" delicious="" "=""><>
cout < "="" for="" you,="" "="">< name><>
return 0;
}
2.在终端输入以下命令进行编译。
xxxx@xxxx-xxxxxx-xxxxxxx-xxxxx:~/文档/cppfile$ g++ test1.cpp
会在同目录下生成一个a.out文件。
3.再输入以下命令运行可执行文件。
xxxx@xxxx-xxxxxx-xxxxxxx-xxxxx:~/文档/cppfile$ ./a.out
Enter your name:
Rawa
Enter your favorite dessert:
Cake
I have some delicious Cake for you, Rawa. //编译运行成功