help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Behavior of ifstream::read()


From: Ulrich Eckhardt
Subject: Re: Behavior of ifstream::read()
Date: Mon, 16 Oct 2006 15:20:12 +0200
User-agent: KNode/0.10.4

Alex Vinokur wrote:
> char cbuffer[BUFFER_SIZE];
> ifstream fs (INPUT_FILE_NAME);
> 
>   fs.clear();
>   fs.seekg (0, ios::beg);
> 
>   while (!fs.eof())
>   {
>     fs.read (cbuffer, sizeof(cbuffer));
>     cout << "rdstate() = 0x" << hex << fs.rdstate() << dec << "; gcount()
= " << fs.gcount() << endl;
>   }

[...]
> Output for g++ (Cygwin)
> --------------------
> rdstate() = 0x6; gcount() = 1499
> rdstate() = 0x6
> -------------------
> It seems that behavior of g++ is wrong here.

There are several stupid things in the code you gave, I won't go into
those. Now, while opening the file, you request that external CR/LF pairs
be converted to an internal '\n'. However, in your file there are LFs that
are not preceeded by CRs, so in fact your file is invalid. At least I
wouldn't be too sure about this being an error, I think Cygwin itself can
also be configured whether its lineendings behaviour should match that of
DOS or of Unix. Disclaimer: I'd have to trace the code myself to see
what's wrong, but take these things into account.

Uli

-- 
http://gcc.gnu.org/faq.html
http://parashift.com/c++-faq-lite/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]