Line up columns of data with cout.width : int display « Data Types « C++ Tutorial






#include <iostream>

using namespace std;

int main()
{
  cout << "Root | Square | Cube\n";
  for(int i = 1; i < 11; ++i) {
    cout.width(4);
    cout << i << " |";
    cout.width(7);
    cout << i * i << " |";
    cout.width(8);
    cout << i * i * i;
    cout << endl;
  }

  return 0;
}








2.5.int display
2.5.1.Displaying Leading Zeros
2.5.2.Change width as you output
2.5.3.setiosflags(ios::left) and resetiosflags(ios::left)
2.5.4.Line up columns of data with cout.width
2.5.5.Using various padding characters
2.5.6.Output decimal to hexadecimal, octal and align the output
2.5.7.Set cout for hex number output