简体   繁体   English

错误消息:“未定义 setw”使用 g++

[英]Error message: "setw is not defined" using g++

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我无法解决此错误,有人可以向我解释此错误背后的原因吗

您需要包含声明它的标头:

#include <iomanip>

Do following two steps:执行以下两个步骤:

  1. include iomanip包括iomanip
  2. write std::setw() instead of setw()写 std::setw() 而不是 setw()

Compile and enjoy...编译并享受...

setw(num) is not defined in iostream library. setw(num) 未在 iostream 库中定义。 So add-所以添加-

#include <iomanip>

in the code and add在代码中添加

using namespace std

it worked for me.它对我有用。

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

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