libstdc++/1019: setw() effect on operator>> for strings off by one?
pcarlini@unitus.it
pcarlini@unitus.it
Sat Dec 9 04:26:00 GMT 2000
>Number: 1019
>Category: libstdc++
>Synopsis: setw() effect on operator>> for strings off by one?
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Dec 09 04:26:01 PST 2000
>Closed-Date:
>Last-Modified:
>Originator: Paolo Carlini
>Release: gcc version 2.97 20001205 (experimental)
>Organization:
>Environment:
Intel PII, GLIBC2.2
>Description:
The following code (by J.W. Reeves) does not work properly:
----------------------
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
using namespace std;
int main()
{
istringstream istrm("08-MAY-2000");
int day, year;
char sep;
string month;
istrm >> day >> sep >> setw(3) >> month >> sep >> year;
cout << "Day=" << day << ", Month=" << month << ", Year=" << year << endl;
return 0;
}
-------------------
Instead of the correct Day=8, Month=MAY, Year=2000, it outputs Day=8, Month=MAY-, Year=0
>How-To-Repeat:
Speaking of setw() and other IO manipulators, on my system, testsuite/27_io/ios_manip_fmtflags.cc outputs:
1 0
true false
:true :
:true:
:false :
: 1:
:1 :
: 0:
yea nay
:yea :
:yea:
:nay :
instead of the expected:
1 0
true false
: true:
:true :
: false:
: 1:
:1 :
: 0:
yea nay
: yea:
:yea :
: nay:
>Fix:
I have perhaps found in line #1126 of include/bits/istream.tcc the cause of the problem. IMHO the comparison __extracted <= __n should read __extracted < __n. In fact, changing it leads to the correct result.
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list