cout: width(), precision(), and fill(). : cout width « Console « C++






cout: width(), precision(), and fill().

cout: width(), precision(), and fill().
 


 
#include <iostream> 
using namespace std; 
 
int main() 
{ 
  cout.setf(ios::showpos); 
  cout.setf(ios::scientific); 
  cout << 123 << " " << 123.23 << endl; 
 
  cout.precision(2);                 // two digits after decimal point 
  cout.width(10);                    // in a field of 10 characters 
  cout << 123 << " "; 
  cout.width(10);                    // set width to 10 
  cout << 123.23 << endl; 
 
  cout.fill('#');                    // fill using # 
  cout.width(10);                    // in a field of 10 characters 
  cout << 123 << " "; 
  cout.width(10);                    // set width to 10 
  cout << 123.23; 
 
  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.Left-justification and right-justification.