This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/11583] New: Cannot reopen file using ifstream
- From: "cwvca at hotmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 Jul 2003 23:08:11 -0000
- Subject: [Bug c++/11583] New: Cannot reopen file using ifstream
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11583
Summary: Cannot reopen file using ifstream
Product: gcc
Version: 3.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: cwvca at hotmail dot com
CC: gcc-bugs at gcc dot gnu dot org
If I run this program:
#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::ifstream textfile;
for (int i = 0; i < 3; i++)
{
std::cout << "Opening Makefile..." << std::endl;
// textfile.clear();
textfile.open("Makefile", std::ios_base::in);
if (!textfile)
{
perror("Cannot open Makefile");
return 1;
}
std::cout << "Reading Makefile..." << std::endl;
char ch;
while (textfile.get(ch))
{
}
std::cout << "Closing Makefile..." << std::endl;
textfile.close();
}
return 0;
}
I get this output:
Opening Makefile...
Reading Makefile...
Closing Makefile...
Opening Makefile...
Cannot open Makefile: Success
If I uncomment the textfile.clear() function, the program works properly. I
shouldn't have to use the clear() function to make this program work. The
open() function should clean everything up before opening the file.