public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: Phil Edwards <pedwards@disaster.jaj.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org Subject: Re: libstdc++/4442: bad fstream behavior <synopsis of the problem (one line)> Date: Tue, 02 Oct 2001 13:46:00 -0000 [thread overview] Message-ID: <20011002204603.8413.qmail@sourceware.cygnus.com> (raw) The following reply was made to PR libstdc++/4442; it has been noted by GNATS. From: Phil Edwards <pedwards@disaster.jaj.com> To: andrew@werdna.com Cc: gcc-gnats@gcc.gnu.org Subject: Re: libstdc++/4442: bad fstream behavior <synopsis of the problem (one line)> Date: Tue, 2 Oct 2001 16:38:04 -0400 On Tue, Oct 02, 2001 at 02:47:54PM -0400, Andrew Haydn Grant wrote: > >Description: > fstreams handle certain odd situations differently than they used to, > causing old code to break. The behavior you're seeing is, unfortunately, unspecified by the standard. Even more unfortunately, the currently recommended resolution is to maintain this behavior. For more, see the C++ homepage linked to from the GCC "Readings" list, and look for LWG defect report 22. (I /must/ remember to add this to the FAQ...) > void fail() > { > fstream f; > f.close(); > f.open("hello.txt", ios::in); > char buffer[2048]; > f.getline(buffer, 2048); > cout << "FILE CONTENTS" << buffer << "FILE CONTENTS\n"; > } > > The fail() function does not read "hello.txt". If you remove the initial > f.close() call, it reads "hello.txt" without difficulty. You can place a call to f.clear() between the close() and the open(), then it will work. Also note that this will /not/ display the entire contents of hello.txt, only the first line. > void failWrite() > { > fstream f; > f.open("/tmp/empire/simout.txt", ios::in); > f.close(); > f.open("/tmp/empire/simout.txt", ios::out); > f << "It went out!!!\n"; > } Likewise, a call to clear() between open() and close() will make this work as you (and the rest of us) expect it to. Phil -- If ye love wealth greater than liberty, the tranquility of servitude greater than the animating contest for freedom, go home and leave us in peace. We seek not your counsel, nor your arms. Crouch down and lick the hand that feeds you; and may posterity forget that ye were our countrymen. - Samuel Adams
next reply other threads:[~2001-10-02 13:46 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2001-10-02 13:46 Phil Edwards [this message] -- strict thread matches above, loose matches on Subject: below -- 2001-10-02 11:56 Andrew Haydn Grant
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20011002204603.8413.qmail@sourceware.cygnus.com \ --to=pedwards@disaster.jaj.com \ --cc=gcc-prs@gcc.gnu.org \ --cc=nobody@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).