[lug] setw(x) (in C++ standard library) on float or double seems to fail in RedHat7.

Robert George Mayer mayer at acm.org
Sun Nov 12 15:20:11 MST 2000


I am having a C++ ostream problem under RedHat Linux 7 with
the
infamous gcc 2.96.

This Small Test Case (TM):
--start code
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    int zero(0);
    int one(1);
    float Zero(0.0);
    float One(1.0);
    double ZERO(0.0);
    double ONE(1.0);

    cout << 15) << 0 << setw(15) << 1 << endl;
    cout << setw(15) << 0.0 << setw(15) << 1.0 << endl;
    cout << setw(15) << zero << setw(15) << one << endl;
    cout << setw(15) << Zero << setw(15) << One << endl;
    cout << setw(15) << ZERO << setw(15) << ONE << endl;
    return 0;
}
-- end code

gives with 2.96:
              0              1
01
              0              1
01
01

and with egcs-2.91.66 in SuSE 6.2
              0              1
              0              1
              0              1
              0              1
              0              1 
Am I missing something or does it seem that setw is broken
for float and 
double in 2.96?

(If you want to Try This At Home just cut and paste the code
into test.C, then compile and run with
c++ test.C
./a.out
)

I would like to know if anyone can shine some light on this.

Thanks.

- BOB
                                                                     
-- 
                       Robert George Mayer
          370 Canyonside Drive  Boulder, Colorado 80302
              303-444-2548            mayer at acm.org





More information about the LUG mailing list