Left-justification and right-justification. : cout width « Console « C++






Left-justification and right-justification.

  
#include <iostream>
#include <iomanip>

using std::cout;
using std::endl;
using std::ios;
using std::setw;
using std::setiosflags;
using std::resetiosflags;

int main()
{
   int x = 12345;

   cout << "Default is right justified:\n"
        << setw(10) << x << "\n\nUsing Member Functions" 
        << "\nUse setf to set ios::left:\n" << setw(10);
   
   return 0;
}
  
    
  








Related examples in the same category

1.Create a table of log10 and log from 2 through 100.Create a table of log10 and log from 2 through 100.
2.Set cout lengthSet cout length
3.cout: width(), precision(), and fill(). cout: width(), precision(), and fill().