// Manipulators: setw; left, right, internal; fixed, scientific // left and right reset each other // fixed and scientific reset each other #include #include using namespace std; int main() { string mystring = "abcde"; double mynum = 33.446; // default cout << "..." << setw(10) << mystring << "..." << setw(10) << mynum << "..." << endl << endl; // left & right reset each other cout << "..." << setw(10) << left << mystring << "..." << setw(10) << fixed << right << setprecision(1) << mynum << "..." << endl; cout << "..." << setw(10) << right << mystring << "..." << setw(10) << fixed << left << setprecision(1) << mynum << "..." << endl; cout << "..." << setw(10) << left << mystring << "..." << setw(10) << fixed << right << setprecision(1) << mynum << "..." << endl << endl; // multiple fixed precisions, inc. overflow cout << "..." << setw(10) << fixed << right << setprecision(1) << mynum << "..." << endl; cout << "..." << setw(10) << fixed << right << setprecision(2) << mynum << "..." << endl; cout << "..." << setw(10) << fixed << right << setprecision(3) << mynum << "..." << endl; cout << "..." << setw(10) << fixed << right << setprecision(4) << mynum << "..." << endl; cout << "..." << setw(10) << fixed << right << setprecision(5) << mynum << "..." << endl; cout << "..." << setw(10) << fixed << right << setprecision(6) << mynum << "..." << endl; cout << "..." << setw(10) << fixed << right << setprecision(7) << mynum << "..." << endl; cout << "..." << setw(10) << fixed << right << setprecision(8) << mynum << "..." << endl << endl; // multiple float precisions, inc. overflow cout << "..." << setw(10) << scientific << right << setprecision(1) << mynum << "..." << endl; cout << "..." << setw(10) << scientific << right << setprecision(2) << mynum << "..." << endl; cout << "..." << setw(10) << scientific << right << setprecision(3) << mynum << "..." << endl; cout << "..." << setw(10) << scientific << right << setprecision(4) << mynum << "..." << endl; cout << "..." << setw(10) << scientific << right << setprecision(5) << mynum << "..." << endl << endl; // now back to fixed cout << "..." << setw(10) << fixed << right << setprecision(5) << mynum << "..." << endl << endl; /* ... abcde... 33.446... ...abcde ... 33.4... ... abcde...33.4 ... ...abcde ... 33.4... ... 33.4... ... 33.45... ... 33.446... ... 33.4460... ... 33.44600... ... 33.446000... ...33.4460000... ...33.44600000... ... 3.3e+01... ... 3.34e+01... ... 3.345e+01... ...3.3446e+01... ...3.34460e+01... ... 33.44600... */ return 0; }