11 Years
Discussion Span
Last Post by vijayan121

can i ask what is the purpose or use of iomanip in C++ ?

to produce formatted output, or to perform operations like flushing the stream, the stream classes privide member functions. eg.

std::cout.width(10) ;
  std::cout.fill('0') ;
  std::cout.setf( ios_base::fixed, ios_base::floatfield ) ;
  std::cout.precision(2) ;
  std::cout << 100.2 << '\n' ;
  std::cout << flush ;

this code is tedious to read (or write).

stream manipulators allow one to embed formatting information as part of the data that is sent to (recd from) the stream. eg.

std::cout <<   std::setw(10) << std::setfill('0') << std::fixed 
                << setprecision(2) << 100.2 << std::endl ;

as such they are a convenient device; they provide syntactic sugar.
jerry schwarz (who wrote the original, now obsolete, iostream library) was inspired by algol's 'layout procedures'.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.