|
ex8-1.cpp - Example 8-1 ios_base fmtflags |
// File: ex8-1.cpp - ios::fmtflags
#include "fmtflags.h"
int main()
{
// save the default fmtflags settings for cout
ios::fmtflags cout_flags = cout.flags();
// print the default cout fmtflags settings value
cout << cout_flags <<endl;
// display the default fmtflags values for cout, cin, cerr, and clog
show_fmtflags(cout);
show_fmtflags(cin);
show_fmtflags(cerr);
show_fmtflags(clog);
// turn on hex for cout
cout.flags(ios::hex);
// display the fmtflags settings for cout
show_fmtflags(cout);
// print some numbers
cout << 12 << ' ' << 123 << ' ' << 1234 << ' ' << 12345 << endl;
// turn on hex and showbase for cout
cout.flags(ios::hex|ios::showbase);
show_fmtflags(cout);
cout << 12 << ' ' << 123 << ' ' << 1234 << ' ' << 12345 << endl;
// turn on hex, showbase, and uppercase for cout
cout.flags(ios::hex|ios::showbase|ios::uppercase);
show_fmtflags(cout);
cout << 12 << ' ' << 123 << ' ' << 1234 << ' ' << 12345 << endl;
// turn on octal for cout
cout.flags(ios::oct);
show_fmtflags(cout);
cout << 12 << ' ' << 123 << ' ' << 1234 << ' ' << 12345 << endl;
// turn on octal and showbase for cout
cout.flags(ios::oct|ios::showbase);
show_fmtflags(cout);
cout << 12 << ' ' << 123 << ' ' << 1234 << ' ' << 12345 << endl;
// reset cout's flags back to the default settings
cout.flags(cout_flags);
show_fmtflags(cout);
cout << 12 << ' ' << 123 << ' ' << 1234 << ' ' << 12345 << endl;
// print out the value for each of the fmtflags constants
cout << "ios::boolalpha=" <<ios::boolalpha << endl;
cout << "ios::dec=" << ios::dec << endl;
cout << "ios::fixed=" << ios::fixed << endl;
cout << "ios::hex=" << ios::hex << endl;
cout << "ios::internal=" << ios::internal << endl;
cout << "ios::left=" << ios::left << endl;
cout << "ios::oct=" << ios::oct << endl;
cout << "ios::right=" << ios::right << endl;
cout << "ios::scientific=" << ios::scientific << endl;
cout << "ios::showbase=" << ios::showbase << endl;
cout << "ios::showpoint=" << ios::showpoint << endl;
cout << "ios::showpos=" << ios::showpos << endl;
cout << "ios::skipws=" << ios::skipws << endl;
cout << "ios::unitbuf=" << ios::unitbuf << endl;
cout << "ios::uppercase=" << ios::uppercase << endl;
return 0;
}
CIS27: Programming in C++ Instructor: Joe Bentley