G
Gunnar G
I'm having problem reading from the beginning of a file.
Here is the code (more or less)
ifstream codefin;
ofstream codefout;
while (not_annoyed)
{
codefout.open("bar");
// write to bar, works fine
codefout.bar();
system("command to change bar to foo");
codefin.open("foo");
if (!codefin.is_open())
cout<<"ERROR: couldn't open foo for reading"<<endl;
cout<<codefin.tellg();
codefin.seekg(0,ios::beg);
cout<<codefin.tellg();
if (codefin.eof())
cout<<"FRACK!\n";
while (!codefin.eof())
getline(codefin,text);
codefin.close();
}
The files foo and bar are there and they look alright, but when I run the
program, at the second run I get the FRACK output. The file foo is not
opened in the beginning. I add the seekg/tellg commands to see, but there
is nothing but -1 and -1 printed.
What have I done wrong?
Here is the code (more or less)
ifstream codefin;
ofstream codefout;
while (not_annoyed)
{
codefout.open("bar");
// write to bar, works fine
codefout.bar();
system("command to change bar to foo");
codefin.open("foo");
if (!codefin.is_open())
cout<<"ERROR: couldn't open foo for reading"<<endl;
cout<<codefin.tellg();
codefin.seekg(0,ios::beg);
cout<<codefin.tellg();
if (codefin.eof())
cout<<"FRACK!\n";
while (!codefin.eof())
getline(codefin,text);
codefin.close();
}
The files foo and bar are there and they look alright, but when I run the
program, at the second run I get the FRACK output. The file foo is not
opened in the beginning. I add the seekg/tellg commands to see, but there
is nothing but -1 and -1 printed.
What have I done wrong?