width.cpp 462 B

123456789101112131415161718192021222324
  1. // width.cpp -- using the width method
  2. #include <iostream>
  3. int main()
  4. {
  5. using std::cout;
  6. int w = cout.width(30);
  7. cout << "default field width = " << w << ":\n";
  8. cout.width(5);
  9. cout << "N" <<':';
  10. cout.width(8);
  11. cout << "N * N" << ":\n";
  12. for (long i = 1; i <= 100; i *= 10)
  13. {
  14. cout.width(5);
  15. cout << i <<':';
  16. cout.width(8);
  17. cout << i * i << ":\n";
  18. }
  19. // std::cin.get();
  20. return 0;
  21. }