std::ios_base::width usage problem

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top