🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #571

Re: Summing a comma delinted file

#571
From: Rich Churcher
Date: Sun, 23 Sep 2001 22:48
49 lines
2278 bytes
"Chris \( Val \)" <chrisvalNOSPAM@NOSPAMbigpond.com.au> writes:

> Hi Wayne, when using the bitwise operator to perform extraction,

Er, that's the stream extraction operator :o)


> it will terminate it's reading upon any whitespace it encounters and
> then move to the next appropriate block of data.

...unless noskipws is used.


[ snip ]
>     if (!instream)
>       {
>         cout << "Input file opening failed.\n";
>         EXIT_FAILURE;

Don't you mean,

  exit( EXIT_FAILURE );

?


>       }
> 
>     if (!outstream)
>       {
>         cout << "Output file opening failed.\n";
>         EXIT_FAILURE;
>       }
> 
>     while (!instream.eof( ))

No, don't do that. eof() only returns true after there has been an
attempt to read past the end of file. Instead, you can test for
success or failure of the input operation:

  while( getline( instream, Record[ Count ], ',' ) )
  {
    // ...

[ examples not compiled or tested ]

-- 
Cheers,  // First time posting?  READ THIS:
Rich.    // http://snurse-l.org/acllc-c++/faq.html
Technical Details
Message-ID: <m3sndd34om.fsf@ihug.com.au>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.kjsl.com!out.nntp.be!propagator-SanJose!news-in!newsfeed.media.kyoto-u.ac.jp!newsfeed.mesh.ad.jp!osa.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!news.tig.com.au!not-for-mail
References: <5vgr7.27572$c5.208712@newsfeeds.bigpond.com> <DJir7.27761$c5.209698@newsfeeds.bigpond.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 114592,a8ecdb8ba824bdd3
X-Google-Attributes: gid114592,public
X-Google-Thread: 103c8d,a8ecdb8ba824bdd3
X-Google-Attributes: gid103c8d,public
X-Google-ArrivalTime: 2001-09-23 15:30:38 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.kjsl.com!out.nntp.be!propagator-SanJose!news-in!newsfeed.media.kyoto-u.ac.jp!newsfeed.mesh.ad.jp!osa.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!news.tig.com.au!not-for-mail
From: Rich Churcher <churcher@ihug.com.au>
Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cppbuilder.language
Subject: Re: Summing a comma delinted file
Date: 24 Sep 2001 08:48:12 +1000
Organization: The Internet Group (Sydney)
Lines: 49
Sender: rich@ihug.com.au
Message-ID: <m3sndd34om.fsf@ihug.com.au>
References: <5vgr7.27572$c5.208712@newsfeeds.bigpond.com> <DJir7.27761$c5.209698@newsfeeds.bigpond.com>
NNTP-Posting-Host: p194-apx1.syd.ihug.com.au
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
X-Trace: bugstomper.ihug.com.au 1001284222 23000 203.173.140.194 (23 Sep 2001 22:30:22 GMT)
User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.1 (Cuyahoga Valley)