how do I reload a static ifstream
I made a function that reads strings from a file. the problem is that if I run the function again, it starts at the end of the file. I thought a .close followed by a .open would make it start from the beginning, but apparently I was wrong.
so, is there a function that closes the file and opens it from the beginning, or just reloads the file?
[352 byte] By [
zoef] at [2007-11-11 11:59:41]

# 1 Re: how do I reload a static ifstream
You can use rewind() or simply use a nonstatic local ifsstream, which will implicitly open (during initialization) and close (during destruction) the same file.
Danny at 2007-11-11 20:55:33 >

# 3 Re: how do I reload a static ifstream
I don't really getwhat danny means, and I haven't the foggiest what amahdy is on about, so I'll throw in the code and you get to fix it, that'll work I think.
this is basically a stripped version of what I need. the function can be called a gazillion times and it will always run down the list in order, and if it's at the end of the file, it starts again from the beginning.
char blabla(){
static ifstream invoer;
static bool passed = false;
if (!passed){
invoer.open(filename);
passed = true;
}
kar = invoer.get();
if (invoer.eof()){
//start again from the beginning
kar = invoer.get();
}
return kar;
}
zoef at 2007-11-11 20:57:33 >
