E
Eddie
On the VC++ 2008 Express, a short example is list below the text.
When I open the fin for the second time in the same scope, it fails.
As far as I know, the close() function reset the error bits, am I
understanding wrong?
I checked error flag and found eofbit and failbit(of course) are still
set after the second open.
ifstream::close() doesn't reset the error bits anymore? Or it never
does?
Please let me know.
Thanks in advance.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char ch;
ifstream fin("test.txt");
if ( fin )
{
while ( fin.get(ch) )
cout << ch;
}
// Set eofbit heres
fin.close();
fin.open("test.txt"); // Reusing fin
if ( !fin )
cout << "File open error" << endl;
fin.close();
return 0;
}
When I open the fin for the second time in the same scope, it fails.
As far as I know, the close() function reset the error bits, am I
understanding wrong?
I checked error flag and found eofbit and failbit(of course) are still
set after the second open.
ifstream::close() doesn't reset the error bits anymore? Or it never
does?
Please let me know.
Thanks in advance.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char ch;
ifstream fin("test.txt");
if ( fin )
{
while ( fin.get(ch) )
cout << ch;
}
// Set eofbit heres
fin.close();
fin.open("test.txt"); // Reusing fin
if ( !fin )
cout << "File open error" << endl;
fin.close();
return 0;
}