AW: problems with ifstream using G++ 3.0.3
Muhammad Ali
Muhammad.Ali@ebp.de
Tue Jun 11 06:42:00 GMT 2002
This is a problem with some operating systems implementations. Like on IRIX
I got the same problem and it is a reported problem on IRIX. It took me a
long time to figure out what is wrong. And then I was forced to use two
ifstream variables. I think you can try to look help for your operating
system. May be you can find a better way or some way that you can use one
ifstream again.
Regards
Muhammad Ali
-----Ursprüngliche Nachricht-----
Von: Edwin Chan/Toronto/IBM [mailto:edwinc@ca.ibm.com]
Gesendet: Dienstag, 11. Juni 2002 15:36
An: gcc-help@gcc.gnu.org
Betreff: problems with ifstream using G++ 3.0.3
Once I read to the end of file and close the ifstream, I can't reopen the
ifstream again.
Ex.
in file foo
first
second
in file bar
second
first
in test.cpp
#include <iostream.h>
#include <fstream.h>
using namespace std;
void foo(ifstream &in) {
while (!in.eof()) {
char ch;
in.get(ch);
cout << ch;
}
in.close();
in.open("bar",ios::ate);
if (in.eof()) cout << "end of file" << endl;
while (!in.eof()) {
char ch;
in.get(ch);
cout << ch;
}
}
int main() {
ifstream in;
in.open("foo");
foo(in);
return 0;
}
//Result
first
second
end of file
More information about the Gcc-help
mailing list