C++ 错误消息:“setw 未定义”使用 g++
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18983745/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error message: "setw is not defined" using g++
提问by anonymous
I am trying to compile using gcc a project which earlier used SunStudio and am getting an error in the following code:
我正在尝试使用 gcc 编译一个之前使用 SunStudio 的项目,但在以下代码中出现错误:
ostream & operator << ( ostream & os, const UtlDuration & d )
{
if ( d._nsec == 0 )
{
os << d._sec << " sec";
return os;
}
else
{
cout.fill( '0' );
os << d._sec << "." << std::setw(9) << d._nsec << " sec";
cout.fill( ' ' );
return os;
}
}
Error: “setw” is not a member of “std”
错误:“setw”不是“std”的成员
I am not able to resolve this error can someone please explain me reason behind this error
我无法解决此错误,有人可以向我解释此错误背后的原因吗
回答by David Heffernan
You need to include the header which declares it:
您需要包含声明它的标头:
#include <iomanip>
回答by Muhammad Kazim Korai
Do following two steps:
执行以下两个步骤:
- include iomanip
- write std::setw() instead of setw()
- 包括iomanip
- 写 std::setw() 而不是 setw()
Compile and enjoy...
编译并享受...