云服务器网:购买云服务器和VPS必上的网站!

ubuntu如何编译cpp

ubuntu如何编译cppubuntu编译cpp的示例:1.编写C++文件,保存为“test1.cpp”。//————-ubuntu上.cpp文件编译与运行#include int main(){using namespace std;cons

ubuntu如何编译cpp

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 name:\n";

cin.getline(name, ArSize);

cout << "Enter your favorite dessert:\n";

cin.getline(dessert, ArSize);

cout << "I have some delicious " << dessert;

cout << " for you, " << name << ".\n";

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. //编译运行成功

本文来源:https://www.yuntue.com/post/75663.html | 云服务器网,转载请注明出处!

关于作者: yuntue

云服务器(www.yuntue.com)是一家专门做阿里云服务器代金券、腾讯云服务器优惠券的网站,这里你可以找到阿里云服务器腾讯云服务器等国内主流云服务器优惠价格,以及海外云服务器、vps主机等优惠信息,我们会为你提供性价比最高的云服务器和域名、数据库、CDN、免费邮箱等企业常用互联网资源。

为您推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注