/* testio1.cpp CIS 150 5/31/2005 David Klick This program demonstrates a number of output formatting techniques used with C++ output streams. */ #include #include using std::cout; using std::endl; using std::setw; using std::setprecision; using std::setfill; using std::left; using std::right; using std::hex; using std::oct; using std::dec; using std::fixed; using std::showpoint; using std::boolalpha; using std::noboolalpha; using std::showbase; using std::noshowbase; using std::uppercase; int main(void) { int n = 42; double x = 78.1544472; bool flag = false; cout << n << '\n'; cout << setw(5) << n << '\n'; cout << setfill('*') << setw(5) << n << '\n'; cout << left << setw(5) << n << '\n'; cout << right << setw(5) << n << '\n'; cout << setfill(' ') << hex << setw(5) << n << '\n'; cout << oct << setw(5) << n << '\n'; cout << showbase << hex << setw(5) << n << '\n'; cout << oct << setw(5) << n << '\n'; cout << uppercase; cout << showbase << hex << setw(5) << n << '\n'; cout << noshowbase << hex << setw(5) << n << '\n'; cout << oct << setw(5) << n << '\n'; cout << dec << setw(5) << n << "\n\n"; cout << x << '\n'; cout << setw(10) << setprecision(5) << x << '\n'; cout << fixed << showpoint; cout << setw(10) << setprecision(5) << x << "\n\n"; cout << flag << '\n'; cout << boolalpha << flag << '\n'; cout << noboolalpha << flag << "\n\n"; return 0; } /* Sample output: 42 42 ***42 42*** ***42 2a 52 0x2a 052 0X2A 2A 52 42 78.1544 78.154 78.15445 0 false 0 */