This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/3750: stream input operator>> fails in g++ 3.0
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/3750: stream input operator>> fails in g++ 3.0
- From: jddahl at micron dot com
- Date: 20 Jul 2001 16:36:33 -0000
- Reply-To: jddahl at micron dot com
>Number: 3750
>Category: c++
>Synopsis: stream input operator>> fails in g++ 3.0
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Jul 20 09:46:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Jeff Dahl
>Release:
>Organization:
>Environment:
SunOS 5.6 Generic_105181-25 sun4m sparc SUNW,SPARCstation-20
>Description:
ANY TEXT FILE:
public class HelloWorld
{
public static void main(String [] args)
{
System.out.println("Hello");
}
}
CODE SOURCE:
#include <iostream>
#include <string>
#include <fstream>
using std::string;
using std::cerr;
using std::cout;
using std::endl;
using std::ifstream;
using std::ios;
int main( int argc, char *argv[] )
{
string fileArg;
ifstream inFile( "/u/jddahl/HelloWorld.java", ios::in );
if( !inFile )
{
cerr << "File could not be opened" << endl;
}
while( !inFile.eof( ))
{
//getline( inFile, fileArg );
inFile >> fileArg;
cout << "[" << fileArg << "]" << endl;
}
return 0;
}
OUTPUT WITH g++ -V 3.0:
{jddahl}67> g++ -V 3.0 test.cpp
{jddahl}68> a.out
[public class Hello]
[orld
{
public static void main(]
[tring ]
[] args)
{
]
[ystem.out.println("Hello");
}
}
]
OUTPUT WITH g++ -V 2.95.3:
{jddahl}69> g++ -V 2.95.3 test.cpp
{jddahl}70> a.out
[public]
[class]
[HelloWorld]
[{]
[public]
[static]
[void]
[main(String]
[[]]
[args)]
[{]
[System.out.println("Hello");]
[}]
[}]
[}]
g++ -V 3.0 output is all messed up-- dropping letters,
grabbing whitespace etc.
>How-To-Repeat:
compile the source file with g++ -V 2.95.3 and g++ -V 3.0 and
compare the output.
>Fix:
use getline and strtok each line
>Release-Note:
>Audit-Trail:
>Unformatted:
gcc version 3.0