[Bug c++/15027] New: Inconsistent ifstream behavior between g++ 3.0.x and 3.3.3 on x86/Linux

drkent at lanl dot gov gcc-bugzilla@gcc.gnu.org
Tue Apr 20 13:51:00 GMT 2004


The code listed below behaves differently when run with g++ 3.0.x and 3.3.3 on
x86 GNU Linux.  With 3.0.x and all earlier GCC compilers I've used, the >>
operator reads one word from the ifstream into temp.  With 3.3.3, the >>
operator reads the entire file into temp.  I have seen the same behavior as
3.3.3 also in the 3.2.3 and 3.2.1 compilers.  To the best of my knowledge, >>
should only read in one word (this is what all other C++ compilers I've used do).

g++ -v gives:
Reading specs from
/users/drkent/code/gcc/gcc_3.3.3/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/specs
Configured with: ./configure --prefix=/users/drkent/code/gcc/gcc_3.3.3
--disable-threads
Thread model: single
gcc version 3.3.3

I have also tried this using the posix threading.


uname -a gives:
Linux l1 2.4.18 #1 SMP Mon Nov 4 11:09:23 MST 2002 i686 unknown


// CODE START

#include <fstream>
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char **argv)
{
  ofstream data("data_ifstream.dat");
  
  for(int i=0; i<10; i++)
    {
      data << i << endl;
    }

  data.close();

  ifstream file("data_ifstream.dat");

  string temp;

  file >> temp;

  cout << "Output should be \"0\" during a correct run:" << endl;
  cout << temp << endl;
}

-- 
           Summary: Inconsistent ifstream behavior between g++ 3.0.x and
                    3.3.3 on x86/Linux
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: drkent at lanl dot gov
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15027



More information about the Gcc-bugs mailing list