This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

libstdc++/1005: setw() does not work with doubles



>Number:         1005
>Category:       libstdc++
>Synopsis:       setw() does not work with doubles
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 07 02:26:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Robert Klima
>Release:        gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
Redhat Linux 7.0
>Description:
setw() does not work if the following object is a double value:
	cout << setw(20) << 2   << endl; // works
	cout << setw(20) << "2" << endl; // works
	cout << setw(20) << 2.3 << endl; // DOES NOT WORK
The following code does not work properly:
=====================================
#include <iostream>
#include <iomanip>

void main ()
{
   cout << setw(20) << 2.3 << endl;
}
=====================================
Instead of formatting the double value 2.3 right aligned
padding with ' ' setw() fills with invilsible '^@'

This can be observed compiling the code with
	g++ -o file file.cc
and running with (!)
	./file | less
>How-To-Repeat:

>Fix:
#include <stdio.h>
#include <iostream>
#include <iomanip>

void main ()
{
   char buffer[200];
   sprintf(buffer, "%g", 2.3);
   cout << setw(20) << buffer << endl;
}
>Release-Note:
>Audit-Trail:
>Unformatted:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]