From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII-7-bit From: =?ISO-8859-1?Q?Falk_Tannh=E4user?= Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng Subject: Re: Teaching new tricks to an old dog (C++ -->Ada) Date: Thu, 10 Mar 2005 12:57:14 +0100 Organization: Canon Research Centre France Message-ID: References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110032222.447846.167060@g14g2000cwa.googlegroups.com> <871xau9nlh.fsf@insalien.org> <3SjWd.103128$Vf.3969241@news000.worldonline.dk> <87r7iu85lf.fsf@insalien.org> <87is4598pm.fsf@insalien.org> <1110054476.533590@athnrd02> <1110059861.560004@athnrd02> <422b6d49.1141887367@news.xs4all.nl> <1110266099.441421.179290@o13g2000cwo.googlegroups.com> <1110332933.587110.260410@z14g2000cwz.googlegroups.com> <1110390097.532139.43430@f14g2000cwb.googlegroups.com> <422f3808$0$30165$ba620e4c@news.skynet.be> <1110409958.685759.249420@g14g2000cwa.googlegroups.com> <1110422853.41859@athnrd02> <42302f4d$0$26544$9b4e6d93@newsread4.arcor-online.net> NNTP-Posting-Host: centre.crf.canon.fr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: s1.news.oleane.net 1110455819 11313 194.2.158.33 (10 Mar 2005 11:56:59 GMT) X-Complaints-To: abuse@oleane.net NNTP-Posting-Date: Thu, 10 Mar 2005 11:56:59 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041217 X-Accept-Language: de, fr, pl, en, en-us In-Reply-To: <42302f4d$0$26544$9b4e6d93@newsread4.arcor-online.net> Path: g2news1.google.com!news4.google.com!news.glorb.com!proxad.net!feed.ac-versailles.fr!oleane.net!oleane!not-for-mail Xref: g2news1.google.com comp.lang.ada:9025 comp.lang.c++:44944 comp.realtime:1193 comp.software-eng:4756 Date: 2005-03-10T12:57:14+01:00 List-Id: Georg Bauhaus wrote: > Ioannis Vranos wrote: > >> For example consider this simple bullet-proof code for string input >> and processing: >> >> >> #include >> #include >> >> int main() >> { >> using namespace std; >> >> string s; >> >> while(cin) >> { >> getline(cin,s); >> >> /*Do things with s */; >> } >> } > > > When I run your program and have it read the null > device, it stops after reading 536870883 bytes if s.length() > is right. This number is 29 bytes less than 2^29; however, > s.max_size() is printed as 1073741820, which is 4 bytes less > than 2^30. The program should read #include #include #include int main() { std::string s; while(std::getline(std::cin, s)) { // Do things with s } return 0; } so that the loop body is not executed after failing of getline(). However, even the original version, while reading from /dev/null, should execute the loop only once and leave the string 's' empty since End Of File should be detected on the first attempt to read a character. Could it be there is something seriously wrong with your compiler / standard library installation? Falk