L
Lu
To teach myself about std::ios_base::width, I make the following program:
[jxlu@edusrv jxlu]$ cat pi.cpp
// modify precision
#include <iostream>
using namespace std;
int
main ()
{
double f = 3.14159265357989;
cout.width (10);
cout.precision (4);
cout << f * 0.01 << ' ' << f * 0.1 << ' ' << f << ' ' << f *
1000000 << endl;
cout.precision (5);
cout << f * 0.01 << ' ' << f * 0.1 << ' ' << f << ' ' << f *
1000000 << endl;
return 0;
}
[jxlu@edusrv jxlu]$ g++ -Wall -o pi pi.cpp
[jxlu@edusrv jxlu]$ ./pi
0.03142 0.3142 3.142 3.142e+06
0.031416 0.31416 3.1416 3.1416e+06
[jxlu@edusrv jxlu]$
But what I want is:
0.03142 0.3142 3.142 3.142e+06
0.031416 0.31416 3.14163.1416e+06
How can I make it?
Sincerely,
Lu
[jxlu@edusrv jxlu]$ cat pi.cpp
// modify precision
#include <iostream>
using namespace std;
int
main ()
{
double f = 3.14159265357989;
cout.width (10);
cout.precision (4);
cout << f * 0.01 << ' ' << f * 0.1 << ' ' << f << ' ' << f *
1000000 << endl;
cout.precision (5);
cout << f * 0.01 << ' ' << f * 0.1 << ' ' << f << ' ' << f *
1000000 << endl;
return 0;
}
[jxlu@edusrv jxlu]$ g++ -Wall -o pi pi.cpp
[jxlu@edusrv jxlu]$ ./pi
0.03142 0.3142 3.142 3.142e+06
0.031416 0.31416 3.1416 3.1416e+06
[jxlu@edusrv jxlu]$
But what I want is:
0.03142 0.3142 3.142 3.142e+06
0.031416 0.31416 3.14163.1416e+06
How can I make it?
Sincerely,
Lu