Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!F.GP.CS.CMU.EDU!David.Detlefs From: David.Detlefs@F.GP.CS.CMU.EDU Newsgroups: gnu.g++.lib.bug Subject: Bug in istream::get Message-ID: <8908051856.AA21241@AENEAS.MIT.EDU> Date: 5 Aug 89 18:56:13 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 47 I am using G++ 1.35 and libg++ 1.35.1. Consider the following program: -------------------------------------------------- #include void main() { filebuf fin; fin.open("bug4-input", input); istream ist(&fin); char s[100]; for (int i = 0; i < 50; i++) s[i] = '#'; ist.get(s, 3); cout << "S is " << s << ".\n"; } -------------------------------------------------- where 'bug4-input' is the file: -------------------------------------------------- 123456789 -------------------------------------------------- When compiled with G++ and libg++, this program prints S is 1234. Note that AT&T cfront (1.2.1 and a beta test of 2.0) do *not* print what you might expect, which is S is 123. Instead, they print S is 12. An argument can be made that this is correct behavior, since Stroustrup p. 237 says "... istream::get reads at most n characters into a character vector starting at p [equivalent to s in this program]." Since get inserts the terminating null character in addition to the characters read, "12\0" are the correct three characters that should be put in s. I am in the process of compiling and testing a fix, which I will post if it works. Dave