This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/14773] New: incorrect behavior of istringstream in gcc 3.2.3
- From: "saunak dot chakrabarti at gs dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 29 Mar 2004 17:19:17 -0000
- Subject: [Bug c++/14773] New: incorrect behavior of istringstream in gcc 3.2.3
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I am using getline to loop through the lines of a file and then tokenizing with
istringstream.
In gcc 2.95, if a getline fetches an empty line from a file (with length=0), an
attempt to do:
std::istringstream s(line);
s >> token;
cout << token << endl;
results in token being empty, which is correct since the underlying line is
empty.
However, in gcc 3.2.3, the same results in token retrieving its previous value
from line.
OUTPUT of test program from gcc 2.95:
line is # $Id: router.config.PTSIPM,v 1.3 2003/11/06 15:29:47 chakrs Exp $
length is 66
token is #
line is
length is 0
token is <---------- NOTE that token is empty here, which is correct
OUTPUT of test program from gcc 3.2.3:
line is # $Id: router.config.PTSIPM,v 1.3 2003/11/06 15:29:47 chakrs Exp $
length is 66
token is #
line is
length is 0
token is # <---------- NOTE that token is set to '#' from the previous read
CODE SAMPLE TO REPRODUCE:
#include <iostream.h>
#include <fstream.h>
#include <sstream>
void printString(char l[])
{
for ( int i=0; l[i] != '\0'; i++ )
cout << l[i];
cout << endl;
}
void fileRd(istream &f)
{
char line[512];
char token[512];
for (;;)
{
f.getline(line, sizeof(line));
if (!f)
{
cerr << "Not f" << endl;
break;
}
else
{
cout << "line is ";
printString(line);
cout << "length is " << strlen(line) << endl;
std::istringstream s(line);
s >> token;
cout << "token is ";
printString(token);
cout << endl;
}
}
}
int main()
{
ifstream f("router.config", ios::in);
if (f.fail())
return 0;
fileRd(f);
return 0;
}
_________________________________________________________________
The input file router.config looks like:
# $Id: router.config.PTSIPM,v 1.3 2003/11/06 15:29:47 chakrs Exp $
(empty line here)
--
Summary: incorrect behavior of istringstream in gcc 3.2.3
Product: gcc
Version: 3.2.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: saunak dot chakrabarti at gs dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14773