|
-
January 28th, 2003, 03:58 AM
#1
Bug in FSTREAM
I'm creating an instance of the IFSTREAM class (ifstream myFile). I'm able to open and read from the file the object is connected to. However after closing the object and then trying to Open again I promptly get an error.
My code looks something like this:
===
ifstream inFile;
inFile.open("e:\\Test.exe", ios::binary);
if (!inFile)
{cout << "File Open Error - Read" << endl; return 0;}
.
.
.
inFile.close();
inFile.open("e:\\Test2.exe", ios::binary);
if (!inFile)
{cout << "File Open Error - Read2" << endl; return 0;}
===
The error occurs for the second if (!inFile). Is this a bug within Visual C++'s implementation of ifstream? When i alter the ifstream object to a pointer (ie. ifstream *inFile) and apply new/delete before the next open all is fine. Why??
-
January 28th, 2003, 06:35 AM
#2
This is not a bug. closing and opening a stream does
not clear its state. Either after closing (or before
trying to open), you need to clear the state:
See Section 13.9.1 of "The C++ Standard Library" by
Josuttis if you have it.
Last edited by Philip Nicoletti; January 28th, 2003 at 07:50 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|