Bug 75112 - std::iomanip and std::ostream not working correctly for std::string
std::iomanip and std::ostream not working correctly for std::string
Status: CLOSED NEXTRELEASE
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
8.0
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
http://groups.google.com/groups?hl=en...
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2002-10-04 12:30 EDT by Tad Marko
Modified: 2007-04-18 12:47 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-10-01 20:09:52 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Tad Marko 2002-10-04 12:30:09 EDT
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-01 20:09:52 EDT
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.