setf.cpp 745 B

123456789101112131415161718192021222324252627
  1. // setf.cpp -- using setf() to control formatting
  2. #include <iostream>
  3. int main()
  4. {
  5. using std::cout;
  6. using std::endl;
  7. using std::ios_base;
  8. int temperature = 63;
  9. cout << "Today's water temperature: ";
  10. cout.setf(ios_base::showpos); // show plus sign
  11. cout << temperature << endl;
  12. cout << "For our programming friends, that's\n";
  13. cout << std::hex << temperature << endl; // use hex
  14. cout.setf(ios_base::uppercase); // use uppercase in hex
  15. cout.setf(ios_base::showbase); // use 0X prefix for hex
  16. cout << "or\n";
  17. cout << temperature << endl;
  18. cout << "How " << true << "! oops -- How ";
  19. cout.setf(ios_base::boolalpha);
  20. cout << true << "!\n";
  21. // std::cin.get();
  22. return 0;
  23. }