Hi,
I have very strange problem with std::fstream. I want to read a simple two-column space-separated file with the following code:
#include <iostream>
#include <fstream>
- int main()
-
{
-
std::ifstream file("file.txt");
-
unsigned long oldval;
-
unsigned long newval;
-
-
while(!file.eof()) {
-
file >> oldval;
-
file >> newval;
-
std::cout << oldval << " " << newval << std::endl;
-
}
-
}
The file.txt contains ten lines only:
- 3036679276 4677957
-
3233819949 6457113
-
3602920021 7347886
-
6236944672 16846074
-
2487223488 3069408
-
2818574689 4363018
-
5419052468 13941073
-
9172944933 31529903
-
2818574690 4363020
-
9172944938 31529909
As output, I get an endless printing of the 3rd line. I have tried a lot of variants, like:
- while(file>>oldval>>newval)
-
while(file.good())
and I always get the same behavior. It looks like the seek internal pointer of fstream is not moving. Any clues about this? I'm in RH with GCC3.4. Thanks for your time.