mickey
12th October 2006, 19:17
hi, my app is similar this below:
fstream file;
while ((choice=getchar()) != '0' ) {
if (!file.open(file_name.c_str(), std::ios_base::in)) { //read only
if ((file()).eof())
cout << "end file \n";
cerr << "unable to open that file\n";
return -1;
}
while ( c=file.get(); ) {
cout.put(ch);
}
f.close();
}
I read all file and at the end of first cycle I close the file; but the second cycle, program terminate because file seems to be at the end. Why? I supposed if I close and re-open it goes at begin....thanks
fstream file;
while ((choice=getchar()) != '0' ) {
if (!file.open(file_name.c_str(), std::ios_base::in)) { //read only
if ((file()).eof())
cout << "end file \n";
cerr << "unable to open that file\n";
return -1;
}
while ( c=file.get(); ) {
cout.put(ch);
}
f.close();
}
I read all file and at the end of first cycle I close the file; but the second cycle, program terminate because file seems to be at the end. Why? I supposed if I close and re-open it goes at begin....thanks