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

ano*_*ous 23 c++

我正在尝试使用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;
    }
}
Run Code Online (Sandbox Code Playgroud)

错误:"setw"不是"std"的成员

我无法解决此错误,有人请解释这个错误背后的原因

Dav*_*nan 51

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

#include <iomanip>
Run Code Online (Sandbox Code Playgroud)