//---------------------------------------------------------------------------- // sample code to show some formatting //---------------------------------------------------------------------------- #include #include #include using namespace std; int const SIZE = 5; int main(){ int myInts[SIZE] = {8, 10, 99, 2, 15}; double myDubs[SIZE] = {32.99, 86.00, 73.279, 25.76432, 59.23}; string myStrings[SIZE] = {"hello", "world", "red", "blue", "purple"}; cout << endl << "No formatting to speak of" << endl; for (int i=0; i < SIZE; i++) { cout << myStrings[i] << " " << myInts[i] << " " << myDubs[i] << endl; } // had a problem using setw for strings, fill by printing blanks cout << endl << "Use setw to make columns" << endl; for (int i=0; i < SIZE; i++) { cout << myStrings[i] << setw(8-myStrings[i].length()) << ' ' << " " << setw(3) << myInts[i] << " " << setw(7) << myDubs[i] << endl; } cout << endl << "Set two places after decimal point" << endl; cout << setprecision(2) << setiosflags(ios::fixed | ios::showpoint); for (int i=0; i < SIZE; i++) { cout << myStrings[i] << setw(8-myStrings[i].length()) << ' ' << " " << setw(3) << myInts[i] << " " << setw(7) << myDubs[i] << endl; } return 0; }