Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error message: "setw is not defined" using g++

Tags:

c++

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

like image 279
anonymous Avatar asked Sep 24 '13 13:09

anonymous


People also ask

What does SETW () do in C++?

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.

Can we use SETW in C?

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.

Which file contains definition of SETW?

Conclusion. The setw() function is a part of the iomanip library which contains the manipulator functions.


2 Answers

You need to include the header which declares it:

#include <iomanip> 
like image 125
David Heffernan Avatar answered Sep 21 '22 19:09

David Heffernan


Do following two steps:

  1. include iomanip
  2. write std::setw() instead of setw()

Compile and enjoy...

like image 37
Muhammad Kazim Korai Avatar answered Sep 20 '22 19:09

Muhammad Kazim Korai