Use a field width of 20 : double output « Data Types « C++ Tutorial






#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
  cout << "Default format: " << 123.123456789 << endl;

  cout << "Use a field width of 20:\n";
  cout << "|" << setw(20) << "Testing" << "|\n\n";
  cout << "Use a field width of 20 with left justification:\n";
  cout << "|" << setw(20) << left << "Testing" << "|\n\n";

  return 0;
}








2.8.double output
2.8.1.Precision of double: setprecision
2.8.2.Use a field width of 20
2.8.3.After setting the showpos and showpoint flags
2.8.4.setw manipulator is useful when repeated field
2.8.5.Return to default format