#include #include #include #include // needed for setw() using namespace std; int main() { double a; a = 123.456; cout << a << endl; cout.setf(ios::scientific); // Sets flag cout << a << endl; cout.unsetf(ios::scientific); // clears flag cout << a << endl; // Always use save/restore instead of set/clear long flagSettings = cout.flags(); // saves flag settings cout.setf(ios::scientific); cout << a << endl; cout.flags(flagSettings); // restore flag settings cout << a << endl; cout.setf(ios::showpoint); cout.precision(2); cout << 2.0 << endl; cout.precision(2); cout << 0.12345 << endl; cout.precision(2); cout << 12345.0 << endl; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout << "$" << 1000000.23 << endl; cout << "$" << setprecision(2) << 1000000. << endl; return 0; }