elow

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

thanks

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'.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.