编译 & 执行 C++ 程序

时间:2021-07-10 05:21:59

编译 & 执行 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();
cout <<setw() <<a<<endl;
cout <<setw()<<b<<endl;
cout <<setw()<<c<<endl;
return ;
}