【发布时间】:2014-03-03 22:46:01
【问题描述】:
我是 C++ 的业余爱好者,我正在学习使用 g++ 通过命令行进行编译。我下载并安装了 Cygwin,但无法使用此代码:
// setprecision example
#include <iostream> // std::cout, std::fixed
#include <iomanip> // std::setprecision
int main () {
double f =3.14159;
std::cout << std::setprecision(5) << f << '\n';
std::cout << std::setprecision(9) << f << '\n';
std::cout << std::fixed;
std::cout << std::setprecision(5) << f << '\n';
std::cout << std::setprecision(9) << f << '\n';
return 0;
}
但是当我运行控制台时
g++ -c Test.cpp
我得到错误:
Test.cpp: In function `int main()':
Test.cpp:9: undeclared variable `fixed' (first use here)
谁能解释错误来自哪里以及如何解决?我试过了
#include <ios>
在我的程序顶部,但它告诉我找不到文件/目录。在 Cygnus 程序的 include\g++\ 子文件夹中,我有一个 iomanip.h 和 iostream 文件,但没有 ios 文件。
【问题讨论】: