This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/11583] New: Cannot reopen file using ifstream


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]