www.digitalmars.com         C & C++   DMDScript  

c++ - iomanipulator setw ( )

reply "Graydon Ekdahl, Ph. D." <gekdahl bellsouth.net> writes:
I have not done much with C++ for several years and was surprised to
discover that setw ( ) does not work as expected in DM C++ and in Gnu
g++.

cout << '[' << setw ( 10 ) << 'X' << ']' << endl;

In Watcom C++ 11.c and in Borland C++ 5.02 the result is:
[          X].

In GNU g++ version about 2.8, I think, and in DMar C++ the result is:
[X].

I have tried a couple of things such as "use namespace std;" and
changing includes from #include <iomanip.h> to #include <iomanip> and
have removed setw ( ) and used cout.width ( ) with some changes in the
code to accommodate but with no success.

Does anyone know why the various compilers behave differently?  What did
I miss?

Thank you for any help.

Graydon Ekdahl
Jun 21 2002
parent "Laurentiu Pancescu" <user invalid.domain> writes:
I think the behaviour you expect is correct.  The '[        X]' is also the
result you get from gcc-2.95.3 with STLport-4.5.3, but unfortunately not
without it.  MSVC6 also displays that.

If you are interested in ISO-C++ compliance, I suggest gcc-2.95.3 (MinGW or
Cygwin) w/ STLport, or Comeau - they are the best!  Unfortunately, DMC is
very much behind standard compliance...


Laurentiu


"Graydon Ekdahl, Ph. D." <gekdahl bellsouth.net> wrote in message
news:3D13A06D.F17C92F4 bellsouth.net...
 I have not done much with C++ for several years and was surprised to
 discover that setw ( ) does not work as expected in DM C++ and in Gnu
 g++.

 cout << '[' << setw ( 10 ) << 'X' << ']' << endl;

 In Watcom C++ 11.c and in Borland C++ 5.02 the result is:
 [          X].

 In GNU g++ version about 2.8, I think, and in DMar C++ the result is:
 [X].

 I have tried a couple of things such as "use namespace std;" and
 changing includes from #include <iomanip.h> to #include <iomanip> and
 have removed setw ( ) and used cout.width ( ) with some changes in the
 code to accommodate but with no success.

 Does anyone know why the various compilers behave differently?  What did
 I miss?

 Thank you for any help.

 Graydon Ekdahl
Jun 25 2002