istream bug

Robert Schweikert rjschwei@mindspring.com
Wed Jan 3 18:58:00 GMT 2001


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




More information about the Gcc mailing list