problem with setw

John Sibert jsibert@soest.hawaii.edu
Thu Apr 5 06:53:00 GMT 2001


the i/o manipulator setw(int) does not appear to work properly when it 
precedes output of a variable of type double.

I just installed the following version of gcc
$ g++ -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.0)

The following code does not execute correctly. It appears to pad the fields 
precceding the double with '^@' (null ?) characters.

#include <iostream.h>
#include <iomanip.h>

int main(void)
{

   double x = 1.2345;
   char  y[]="2.3456";
   int   z =  345678;
   cout << x << endl;
   cout << y << endl;
   cout << z << endl;
   cout << "double: " << setw(15) << x << setw(15) << x << endl;
   cout << "char[]: " << setw(15) << y << setw(15) << y << endl;
   cout << "int:    " << setw(15) << z << setw(15) << z << endl;
   cout << "double: " << setw(15) << x << setfill('x') << setw(15) << x << 
endl;
   cout << "char[]: " << setw(15) << y << setfill('y') <<  setw(15) << y << 
endl;
   cout << "int:    " << setw(15) << z << setfill('z') << setw(15) << z << 
endl;
   return(0);
}
____________________________________

John Sibert, Manager
Pelagic Fisheries Research Program
University of Hawaii at Manoa
1000 Pope Road
Honolulu, HI 96822
United States

Phone: (808) 956-7895
Fax: (808) 956-4104
____________________________________

Washington DC
Phone: (202) 861 2363
Fax: (202) 861 4767
____________________________________

PFRP Web Site:   http://www.soest.hawaii.edu/PFRP/
email:  jsibert@soest.hawaii.edu
_________________________________









More information about the Gcc-bugs mailing list