Hello all,

 

I’ve ported a simple piece of code from VS2012 to Qt Creator (using MinGW 4.7, or even 4.8 manually installed) and I have a problem using tellg() on a file stream.

Here’s the code:

// Open input file stream

ifstream ifs("Test Element.txt");

if (!ifs)

        throw runtime_error("Couldn't open the input file!");

 

// Find the beginning of the Element Data section

string line;

while (getline(ifs, line, '\n'), line != "$* ELEMENT DATA")

{      

        if (ifs.eof())

        {

               cout << "Cannot find Species Data!!" << endl;

               return 0;

        }

}

 

// Save the beginning of the Element Data section

streampos begin = ifs.tellg();

and here’s the text file:

!File di prova per testare la routine di gestione degli elementi
 
$* ELEMENT DATA
C  .1201070000D+02 CO2          CO2          .3700000000D-03
H  .1007940000D+01 H2O          H2O          .0000000000D+00
N  .1400670000D+02 N2           N2           .7809000000D+00
O  .1599940000D+02 O2           O2           .2095000000D+00
$* END OF ELEMENT DATA

In VS, I get begin == 85, and after using ifs.seekg(begin), a getline yields, correctly, the following line:

C  .1201070000D+02 CO2          CO2          .3700000000D-03

Using MinGW, begin == 94 and the line read is:

70000D+02 CO2          CO2          .3700000000D-03

I’ve searched the internet and found that VS silently discards \r when it’s followed by a \n, whereas MinGW reads that char as well. Then why does tellg() account for all \r but seekg() does not?

 

Thanks in advance, forgive me if I’ve made some mistake in the email, it’s my first one in any mailing list ever J

 

Andrea