当前位置: 移动技术网 > 移动技术>移动开发>IOS > 编译 & 执行 C++ 程序如何编译并运行它

编译 & 执行 C++ 程序如何编译并运行它

2020年07月23日  | 移动技术网移动技术  | 我要评论

编译 & 执行 C++ 程序
接下来让我们看看如何把源代码保存在一个文件中,以及如何编译并运行它。下面是简单的步骤:
打开一个文本编辑器,添加上述代码。
保存文件为 hello.cpp。
打开命令提示符,进入到保存文件所在的目录。
键入 'g++ hello.cpp ‘,输入回车,编译代码。如果代码中没有错误,命令提示符会跳到下一行,并生成 a.out 可执行文件。
现在,键入 ’ a.out’ 来运行程序。
您可以看到屏幕上显示 ’ Hello World '。

#include <iostream>
#include <iomanip>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
    double
     a=123.345,
     b=3.14153,
     c=-3214.67;

     cout <<setiosflags(ios::fixed)<<setiosflags(ios::right)<<setprecision(2);
     cout <<setw(10) <<a<<endl;
     cout <<setw(10)<<b<<endl;
     cout <<setw(10)<<c<<endl;
    return 0;
}

本文地址:https://blog.csdn.net/csdnborter/article/details/107447839

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网