This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

c++/3750: stream input operator>> fails in g++ 3.0



>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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]