Re: ifstream limitations?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Doug Harrison [MVP] wrote:
> [...]
> The while loop was:
>
>> while(in.good())
>> {
>
> [...]
>
> Both these approaches ignore the fact that EOF is
> discovered only when a read is attempted. The while loop
> above will discover EOF when it calls getline and may
> attempt to output a spurious empty string.

Agreed. It was written only as demonstration how to read
something from input file stream. I should have wrote it
with std::copy instead:

ifstream in("C:\\TEMP\\test.txt");

if(in.is_open())
{
copy(istream_iterator<string>(in),
istream_iterator<string>(),
ostream_iterator<string>(cout, "\n"));

in.close();
}



.



Relevant Pages

  • Email Sending - How To
    ... I need to write a batch app. ... that will loop thru data, ... while (not Eof) do begin ... Prev by Date: ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: For Each
    ... Do While .EOF = False ... > How would you loop through the field in each record using the ... > single form mode, not continious? ... Prev by Date: ...
    (microsoft.public.access.formscoding)
  • Checking for EOF with Streamreader
    ... What is the best way to check for EOF when using the streamreader? ... Following is what I have tried but all end in an error when eof is reached. ... Adding 'until line is nothing' to the end of the loop. ... Prev by Date: ...
    (microsoft.public.dotnet.languages.vb)
  • Re: SQL for Quering Access Tables from a Table/Field List Table
    ... from Do until .EOF to End With, and I am prompted to enter the value ... Apparently when there is nothing in the record set it breaks ... out of the loop. ... Prev by Date: ...
    (microsoft.public.access.externaldata)
  • Re: detab utility challenge.
    ... I know he is not suggesting anyone write such a silly loop. ... Once the character returned is EOF, ... Once getc returns EOF (by the way, ...
    (comp.lang.c)