I am trying to compile using gcc a project which earlier used SunStudio and am getting an error in the following code:
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”
I am not able to resolve this error can someone please explain me reason behind this error
setw function is a C++ manipulator which stands for set width. The manipulator sets the ios library field width or specifies the minimum number of character positions a variable will consume. In simple terms, the setw C++ function helps set the field width used for output operations.
Bookmark this question. Show activity on this post. In c++, setw function is used to set the number of characters to be used as the field width for the next insertion operation.
Conclusion. The setw() function is a part of the iomanip library which contains the manipulator functions.
You need to include the header which declares it:
#include <iomanip>
Do following two steps:
Compile and enjoy...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With