【问题标题】:Cygwin g++ doesn't recognize "fixed" as part of the STD libraryCygwin g++ 不将“固定”识别为 STD 库的一部分
【发布时间】: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 文件。

【问题讨论】:

    标签: c++ cygwin fixed


    【解决方案1】:

    您需要#include &lt;ios&gt;iostream 不需要包含很多,也不需要声明fixed

    【讨论】:

    • 可惜了。恕我直言,如果要求声明fixed禁止这样做会更好。将其留给每个实现都会使编写可移植代码变得不必要地困难。
    • 是的,尽管获得正确的细节会很复杂并且可能过度约束实施者。最近在 gcc 的库中做了很多工作,以尽量减少每个 header 拖入的内容,但这并非易事。
    猜你喜欢
    • 1970-01-01
    • 2012-04-02
    • 1970-01-01
    • 2019-06-28
    • 2018-11-20
    • 2015-08-16
    • 2015-10-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多