// iomanip // iomanip (input/output manipulators) is a library that helps // you to edit what you ouptput to the console or a file (make it // look pretty). There are several useful features that you will // likely use often in this course. #include #include using namespace std; int main() { double num = 5; // setw //output is automatically right justified // you can use the left manipulator to change this cout << "with no formatting: " << num << endl; cout << "with setw(5) :" << setw(5) << num << endl; cout << "with setw(10):" << setw(10) << num << endl << endl; // setprecision //setprecision by itself will round off the number based on the //parameter that you give it. num = 5.133333323; cout << "set 1: " << setprecision(1) << num << endl; cout << "set 2: " << setprecision(2) << num << endl; cout << "set 3: " << setprecision(3) << num << endl; cout << "set 4: " << setprecision(4) << num << endl; cout << "set 5: " << setprecision(5) << num << endl << endl; num = 12345678.99; cout << "Here is a problem with setprecision: " << setprecision(5) << num << endl << endl; //if you want to have fixed point notation use the fixed manipulator cout << "fixed 2: " << setprecision(2) << fixed << num << endl; cout << "fixed 3: " << setprecision(3) << fixed << num << endl; cout << "fixed 4: " << setprecision(4) << fixed << num << endl << endl; cout.unsetf(ios::fixed); //this notice how with showpoint setprecision displays a number // with a total of at least 6 digits in length num = 50; cout << "showpoint 6: " << setprecision(6) << showpoint << num << endl; return 0; }