简体   繁体   English

Cygwin g ++不识别“固定”作为STD库的一部分

[英]Cygwin g++ doesn't recognize “fixed” as part of the STD library

I'm an amateur with C++ and I'm learning to compile by command line using g++. 我是C ++的业余爱好者,我正在学习使用g ++通过命令行编译。 I downloaded and installed Cygwin and I can't get this code to work: 我下载并安装了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;

} }

But when I run the console 但是当我运行控制台时

g++ -c Test.cpp

I get the error: 我收到错误:

Test.cpp: In function `int main()':
Test.cpp:9: undeclared variable `fixed' (first use here)

Can anyone explain where the error comes from and how I can fix it? 任何人都可以解释错误的来源以及我如何解决它? I tried 我试过了

#include <ios>

at the top of my program but it tells me that the file/directory can't be found. 在我的程序的顶部,但它告诉我无法找到文件/目录。 In the include\\g++\\ subfolder of my Cygnus program I have an iomanip.h and iostream file but no ios file. 在我的Cygnus程序的include \\ g ++ \\子文件夹中,我有一个iomanip.h和iostream文件但没有ios文件。

You need #include <ios> . 你需要#include <ios> iostream is not required to include very much, and needn't declare fixed . iostream不需要包含很多,也不需要声明fixed

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM