>Submitter-Id: net >Originator: Roger Leigh >Organization: N/A >Confidential: no >Synopsis: libstdc++: ifstream::open() does not work on used ifstream >objects >Severity: serious >Priority: medium >Category: libstdc++ >Class: sw-bug >Release: 3.1.1 20020703 (Debian prerelease) (Debian testing/unstable) >Environment: System: Linux whinlatter 2.4.18 #6 Thu Jul 11 11:41:55 BST 2002 i686 unknown Architecture: i686
host: i386-pc-linux-gnu build: i386-pc-linux-gnu target: i386-pc-linux-gnu configured with: /mnt/data/gcc-3.1/gcc-3.1-3.1.1ds2/src/configure -v --enable-languages=c,c++,java,f77,proto,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/g++-v3-3.1 --enable-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --enable-clocale=gnu --enable-__cxa_atexit --enable-threads=posix --enable-java-gc=boehm --enable-objc-gc i386-linux >Description: The following code works with g++-2.95, but not g++-3.0 or g++-3.1 (example). For the latter two, re-using the same ifstream object (ifstream::open()) results in failure. Defining and using a new ifstream object is OK. Test output (g++-3.1): [EMAIL PROTECTED]:~/cc/16$ ./test2 Open(1) succeeded Current file contents: [file contents] ***EOF*** Unable to open filename for appending. Test output (6++-2.95): [EMAIL PROTECTED]:~/cc/16$ ./test2 Open(1) succeeded Current file contents: [file contents] ***EOF*** Open(2) succeeded Note the second open fails for g++ 3.1. I'm willing to provide any additional data you might require. My system is Debian GNU/Linux (sid). As my incoming email is broken right now (at the ISP), I might not be reachable. My phone number is +44 01254 664642 (UK). >How-To-Repeat: If lines 16-23 are commented out, it will run successfully (gcc 3.0 and 3.1) otherwise both will fail to reopen the file (but gcc 2.95.2 will succeed). #include <fstream> #include <iostream> using std::cout; using std::ifstream; int main() { char* filename = "filename"; ifstream infile(filename); if (!infile) { cout << "Unable to open " << filename << " for reading.\n"; return 1; } cout << "Open(1) succeeded\n"; if (infile) { cout << "Current file contents:\n"; char ch; while (infile.get(ch)) cout << ch; cout << "\n***EOF***\n"; } infile.close(); infile.open(filename); if (!infile) { cout << "Unable to open " << filename << " for appending.\n"; return 1; } cout << "Open(2) succeeded\n"; // read file again infile.close(); return 0; } >Fix: None, sorry. I'm only just learning C++, and found this error when I was learning about iostream and file I/O. -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]