* istream bug
@ 2001-01-03 18:58 Robert Schweikert
2001-01-04 11:28 ` Alexandre Oliva
0 siblings, 1 reply; 3+ messages in thread
From: Robert Schweikert @ 2001-01-03 18:58 UTC (permalink / raw)
To: gcc
When using the "ios::nocreate" opening mode on an istream the file
pointer moves to the end of the file which causes the read with the
stream operator ">>" to fail. I realize that using "ios::nocreate" on an
istream doesn't make a whole lot of sense, however, I think the compiler
should either ignore this opening mode on the istream or issue a warning
or error message. Putting the file pointer to the end of the file
produces behavior that is hard to track down.
The attached file illustrates the problem.
-> g++ -o strTestNb strTest.C
-> ./strTestNb
First Flag: 0
Second Flag: 1
Third Flag: 0
This is buffer: Assembly-1
This is n: 1
This is i: 0
->
-> g++ -o strTest -DDEMOBUG strTest.C
-> ./strTest
This is i: 66267
This is i: 66268
This is i: 66269
This is i: 66270
This is i: 66271
This is i: 66272
This is i: 66273
This is an endless loop.
A fix is appreciated.
Thanks,
Robert
--
Robert Schweikert MAY THE SOURCE BE WITH YOU
rjschwei@mindspring.com LINUX
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: istream bug
2001-01-03 18:58 istream bug Robert Schweikert
@ 2001-01-04 11:28 ` Alexandre Oliva
0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Oliva @ 2001-01-04 11:28 UTC (permalink / raw)
To: Robert Schweikert; +Cc: gcc
On Jan 4, 2001, Robert Schweikert <rjschwei@mindspring.com> wrote:
> When using the "ios::nocreate" opening mode on an istream the file
> pointer moves to the end of the file which causes the read with the
> stream operator ">>" to fail.
Wouldn't it be the case that you failed to specify that the stream is
for input? By passing ios::nocreate, you overrode the default
argument that is ios::input (sp?), so you should have ORed
ios::nocreate to ios::input to get an input stream. Yes, it's
counter-intuitive, but that's the way it is implemented.
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist *Please* write to mailing lists, not to me
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Istream bug
@ 2001-01-04 12:01 Benjamin Kosnik
0 siblings, 0 replies; 3+ messages in thread
From: Benjamin Kosnik @ 2001-01-04 12:01 UTC (permalink / raw)
To: gcc
Please note that nocreate is not in iso 14882. As such it is no longer
supported.
-benjamin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-01-04 12:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-01-03 18:58 istream bug Robert Schweikert
2001-01-04 11:28 ` Alexandre Oliva
2001-01-04 12:01 Istream bug Benjamin Kosnik
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).