#include #include #include using namespace std; int main() { ios_base::fmtflags save = cout.flags(); cout << hex << "cout.flags() == " << save << "\n" << "ios_base::dec == " << ios_base::dec << "\n" << "ios_base::hex == " << ios_base::hex << "\n" << "ios_base::oct == " << ios_base::oct << "\n" << "ios_base::basefield == " << ios_base::basefield << "\n"; if (cout.flags() & ios_base::hex) { cout << "The hex flag is set.\n"; } ios_base::fmtflags myflags = ios_base::dec | ios_base::hex; //Turn on myflags; turn off all others. cout.flags(myflags); //Outside of the basefield, leave all flags unchanged. //Within the basefield, turn on myflags and turn off the others. cout.setf(myflags, ios_base::basefield); //Turn on myflags; leave the others unchanged. cout.setf(myflags); //Turn on myflags; leave the others unchanged. cout << setiosflags(myflags); //Turn off myflags; leave the others unchanged. cout.unsetf(myflags); //Turn off myflags; leave the others unchanged. cout << resetiosflags(myflags); cout.flags(save); //restore all the format flags, not just 3 base flags return EXIT_SUCCESS; }