Change cout width and precision for string and float number output : float output « Data Type « C++






Change cout width and precision for string and float number output

  
#include <iostream>
using namespace std; 
int main(void)
{
   cout.precision(4);
   cout.width(10);
   cout << 10.12345 << endl;
   cout.width(10);
   cout.fill('-');
   cout << 10.12345 << endl;
   cout.width(10);
   cout << "Hi!" << endl;
   cout.width(10);
   cout.setf(ios::left);
   cout << 10.12345;
}
  
    
  








Related examples in the same category

1.Set precision for float number
2.Output float number with fixed flag
3.Output float type number with scientific format
4.Output float in default floating-point format
5.Floating-point values in system default, scientific, and fixed formats.
6.Controlling precision of floating-point values