Mega Code Archive

 
Categories / C++ Tutorial / Development
 

Fixed-point mode, show a + for positive nums, show 3 digits to the right of the decimal

#include <iostream> #include <iomanip> #include <string> using namespace std; int main( ) {    ios_base::fmtflags flags = cout.flags( );    double pi = 3.14285714;    cout << "pi = " << fixed                     << showpos                              << setprecision(3)         << pi << '\n';        cout.flags(flags); } pi = +3.143