std::ios_base::width usage problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lu

    std::ios_base::width usage problem

    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.1415926535798 9;
    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+0 6

    How can I make it?

    Sincerely,
    Lu


Working...