Bug 75112 - std::iomanip and std::ostream not working correctly for std::string
Summary: std::iomanip and std::ostream not working correctly for std::string
Keywords:
Status: CLOSED NEXTRELEASE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 8.0
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL: http://groups.google.com/groups?hl=en...
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-10-04 16:30 UTC by Tad Marko
Modified: 2007-04-18 16:47 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2004-10-02 00:09:52 UTC
Embargoed:


Attachments (Terms of Use)

Description Tad Marko 2002-10-04 16:30:09 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.0) Gecko/20020530

Description of problem:
Using std::iomanip on std::ostream with std::string to pad output does not work
the same as it does for char*.

Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
#include <iostream>
#include <iomanip>
#include <sstream>

using namespace std;

main()
{
    char*  c("CHAR");
    string s("STRING");

    {
        ostringstream buffer;
        cout << "In a 10 char wide field:\n";
        buffer << "|" << setw(10) << c << "|";
        cout << buffer.str() << "\t";
    }
    {
        ostringstream buffer;
        buffer << "|" << setw(10) << s << "|";
        cout << buffer.str();
    }

    cout << "\n\n";

    {
        ostringstream buffer;
        cout << "In a 10 char wide field, left justified:\n";
        buffer << "|";
        buffer.setf(ios::left);
        buffer << setw(10) << c << "|";
        cout << buffer.str() << "\t";
    }
    {
        ostringstream buffer;
        buffer << "|";
        buffer.setf(ios::left);
        buffer << setw(10) << s << "|";
        cout << buffer.str();
    }

    cout << "\n\n";

    {
        ostringstream buffer;
        cout << "In a 10 char wide field, left justified, zero
padded:\n";
        buffer << "|";
        buffer.setf(ios::left);
        buffer << setw(10) << setfill('0') << c << "|";
        cout << buffer.str() << "\t";
    }
    {
        ostringstream buffer;
        buffer << "|";
        buffer.setf(ios::left);
        buffer << setw(10) << setfill('0') << s << "|";
        cout << buffer.str();
    }

    cout << "\n\n";
}

Actual Results:  In a 10 char wide field:
|      CHAR|	|STRING         |
char* and std::string output do not match:

In a 10 char wide field, left justified:
|CHAR      |	|STRING|         

In a 10 char wide field, left justified, zero padded:
|CHAR000000|
|STRING|000000000

Expected Results:  char* and std::string output should be padded similarly.

Additional info:

Before entering this bug here, I posted to comp.lang.c++ and my first response
was from P.J. Plauger himself, who agrees this is aberrant behavior. The
attached URL is for the thread for that post on Google Groups.

Comment 1 Benjamin Kosnik 2004-10-02 00:09:52 UTC
Fixed 3.2.3, 3.3.x, 3.4.x.


Note You need to log in before you can comment on or make changes to this bug.