This is the mail archive of the gcc-bugs@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++/2647: ostringstream with ios::right,ios::adjustfield,setw



>Number:         2647
>Category:       libstdc++
>Synopsis:       ostringstream with ios::right,ios::adjustfield,setw
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Apr 25 14:16:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Francois Gygi
>Release:        gcc version 2.96 20000731
>Organization:
>Environment:
Linux 2.2.16-23 i686 (Red Hat Linux 7.0)
>Description:
ostringstream ignores a
setf(ios::right,ios::adjustfield) statement followed by
a setw(20).
Resulting string obtained from str() is incorrectly
aligned.

Note: the correct result is obtained with Compaq C++V6.3-008,
IBM VisualAge C++ 5, and KAI's KCC 3.4d compilers.  
>How-To-Repeat:
compile with
g++ t.C
execute with 
a.out
>Fix:
use the deprecated ostrstream class instead of
ostringstream: works under gcc version 2.95.2 19991024
(but not with  gcc version 2.96 20000731),
Not a real fix since strstream's are deprecated.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="t.C"
Content-Disposition: inline; filename="t.C"

#include<sstream>
#include<string>
#include<iostream>
#include<iomanip>
using namespace std;

int main()
{
  double a = 3.14159;
  ostringstream st;

  st.setf(ios::right,ios::adjustfield);
  st << setw(20) << a;

  cout << endl;
  cout << "output:" << endl;
  cout <<  st.str() << endl;
  cout << "12345678901234567890" << endl;

  cout << endl;
  cout << "output should be:" << endl;
  cout << "             3.14159" << endl;
  cout << "12345678901234567890" << endl;

  return 0;
}


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