[Bug libstdc++/16385] New: istream floating point input (on linux system)

nicholas dot walker at desy dot de gcc-bugzilla@gcc.gnu.org
Tue Jul 6 15:32:00 GMT 2004


Floating point input using an istream (tested ifstream and cin) fails after 
reading the first floating point number. This behaviour seems to appear after 
version 3.3 (supplied code runs as expected on version 3.2, gives the same 
erroneous behaviour under 3.4).

gcc -v output:

Reading specs from /afs/desy.de/products/gcc-3.3/spec/@sys/bin/../lib/gcc-
lib/i686-pc-linux-gnu/3.3.4/specs
Configured with: ../gcc-3.3.4/configure --prefix=/products/gcc-3.3
Thread model: posix
gcc version 3.3.4

compiled code using the following command line:

g++ -o atest -save-temps test.cpp -static

test code:

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

using namespace std;

void WriteFile(const char*);
void ReadFile(const char*);

int main() {

  const char* fname = "ftest.dat";

  WriteFile(fname);
  ReadFile(fname);

  return 0;
}

void WriteFile(const char* fname)
{
  ofstream fos(fname);
  fos<<10.0<<" ";
  fos<<20.0<<" ";
  fos<<30.0<<endl;
  fos<<40.0<<" ";
  fos<<50.0<<" ";
  fos<<60.0<<endl;
}

void ReadFile(const char* fname)
{
  ifstream fis(fname);

  double x;

  while(fis) {
    x=-99;
    fis>>x;
    cout<<x<<(fis.good() ? " OK" : " BAD")<<endl;
  }
}

output when run:

10 OK
-99 BAD

Not sure how to attach the test.ii file ??

-- 
           Summary: istream floating point input (on linux system)
           Product: gcc
           Version: 3.3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: nicholas dot walker at desy dot de
                CC: gcc-bugs at gcc dot gnu dot org


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



More information about the Gcc-bugs mailing list