〜性状:: EOF()? [英] ~traits::eof()?

查看:79
本文介绍了〜性状:: EOF()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,


获得非文件结束价值最安全的方法是什么?

char_traits< char_type> :: eof()会让我得到eof,但我怎样才能安全地和
一致地产生一个不是eof的价值?我应该使用

~char_traits< char_type> :: eof()? char_traits< char_type> :: int_type()?

char_traits< char_type> :: eof()+ 1?

while(!char_traits< char_type> :: not_eof(char_traits) < char_type> :: int_type(rand())))?


mark

Good day,

What is the safest way to get a non-end of file value?
char_traits<char_type>::eof() will get me eof, but how can I safely and
consistently generate a value that is not eof? should i use
~char_traits<char_type>::eof()? char_traits<char_type>::int_type()?
char_traits<char_type>::eof() + 1?
while(!char_traits<char_type>::not_eof(char_traits <char_type>::int_type(rand())))?

mark

推荐答案



" Mark A. Gibbs" < X _ ********* @ rogers.com_x>在消息中写道

news:vR ********** @ news04.bloor.is.net.cable.rogers .com ...

"Mark A. Gibbs" <x_*********@rogers.com_x> wrote in message
news:vR**********@news04.bloor.is.net.cable.rogers .com...
好一天,

获得非文件结束价值的最安全的方法是什么?
char_traits< char_type> :: eof()会让我知道,但我怎样才能安全和
始终生成一个不是eof的值?我应该使用
~char_traits< char_type> :: eof()? char_traits< char_type> :: int_type()?
char_traits< char_type> :: eof()+ 1?

while(!char_traits< char_type> :: not_eof(char_traits< char_type> :: int_type(rand

())))?
标记
Good day,

What is the safest way to get a non-end of file value?
char_traits<char_type>::eof() will get me eof, but how can I safely and
consistently generate a value that is not eof? should i use
~char_traits<char_type>::eof()? char_traits<char_type>::int_type()?
char_traits<char_type>::eof() + 1?
while(!char_traits<char_type>::not_eof(char_traits <char_type>::int_type(rand
())))?
mark




我觉得你对eof()很困惑。它是一个函数,而不是一个值。


在流上调用eof()会检查流是否已经到达结尾了

之前从流。从流中读取时,您会读到

读取失败。然后你可以检查失败是由于到达

结束(如预期)还是由于某种意外失败(错误)。你不需要检查输入并测试它是否为eof值,也不是非eof

值,因为没有首先是这样的价值。


此外,在C ++中,〜符号不用作不。运营商。该符号是用于表示析构函数的
。的!符号是合乎逻辑的。但正如我之前说过的那样,它与之前的
无关,它与eof()无关,这是一个函数,而不是一个值。


-Howard




I think you are confused about eof(). It is a function, not a value.

Calling eof() on a stream checks if the stream has reached the end by a
previous read from the stream. When reading from a stream, you read until
reading fails. Then you can check if the failure was due to reaching the
end (as expected) or due to some kind of unexpected failure (an error). You
don''t check the input and test it for being an "eof value", nor a "non-eof
value", because there is no such value in the first place.

Also, in C++, the ~ symbol is not used as a "not" operator. That symbol is
used to denote a destructor. The ! symbol is logical not. But as I stated
before, it has nothing to do with eof(), which is a function, not a value.

-Howard



" Howard" <人***** @ hotmail.com>在消息中写道

新闻:Pc ********************* @ bgtnsc04-news.ops.worldnet.att.net ...
"Howard" <al*****@hotmail.com> wrote in message
news:Pc*********************@bgtnsc04-news.ops.worldnet.att.net...
" Mark A. Gibbs" < X _ ********* @ rogers.com_x>在消息中写道
新闻:vR ********** @ news04.bloor.is.net.cable.rogers .com ...
"Mark A. Gibbs" <x_*********@rogers.com_x> wrote in message
news:vR**********@news04.bloor.is.net.cable.rogers .com...
美好的一天, char_traits< char_type> :: eof()会让我自信,但我怎样才能安全和持续生成一个不是eof的值?我应该使用
~char_traits< char_type> :: eof()? char_traits< char_type> :: int_type()?
char_traits< char_type> :: eof()+ 1?
Good day,

What is the safest way to get a non-end of file value?
char_traits<char_type>::eof() will get me eof, but how can I safely and
consistently generate a value that is not eof? should i use
~char_traits<char_type>::eof()? char_traits<char_type>::int_type()?
char_traits<char_type>::eof() + 1?



while(!char_traits< char_type> :: not_eof(char_traits < char_type> :: int_type(rand())))?


while(!char_traits<char_type>::not_eof(char_traits <char_type>::int_type(rand ())))?




我认为你对eof()感到困惑。它是一个函数,而不是一个值。

在流上调用eof()检查流是否已经从流中读取了之前的结尾。从流中读取时,您会阅读,直到读取失败。然后你可以检查故障是由于到达结束(如预期)还是由于某种意外故障(错误)。

mark

I think you are confused about eof(). It is a function, not a value.

Calling eof() on a stream checks if the stream has reached the end by a
previous read from the stream. When reading from a stream, you read until
reading fails. Then you can check if the failure was due to reaching the
end (as expected) or due to some kind of unexpected failure (an error).



你没有''检查输入并测试它是eof值,也不是非eof值,因为首先没有这样的值。


我认为你对char_traits< char_type> :: eof()感到困惑。它没有检查文件结尾,因为feof函数在< stdio.h>中声明了

。相反,它返回适合于char_type元素流的文件结尾代码

。你*检查你从流缓冲区获得的输入是否为
并测试它是否为eof值。

另外,在C ++中,〜符号是不用作不运营商。符号
用于表示析构函数。的!符号是合乎逻辑的。但正如我之前提到的b $ b,它与eof()无关,它是一个函数,而不是一个值。


You don''t check the input and test it for being an "eof value", nor a "non-eof
value", because there is no such value in the first place.
I think you are confused about char_traits<char_type>::eof(). It
doesn''t check for end-of-file, as does the feof function declared
in <stdio.h>. Rather, it returns the end-of-file code suitable
for a stream of char_type elements. You *do* check the input you
obtain from a stream buffer and test it for being an "eof value".
Also, in C++, the ~ symbol is not used as a "not" operator. That symbol is used to denote a destructor. The ! symbol is logical not. But as I stated before, it has nothing to do with eof(), which is a function, not a value.




此外,在C ++中〜符号*也*用作不。运营商。那个

符号用于表示按位反转。当应用于eof()返回的

值时,很可能会将其更改为值
,该值不等于eof()。


PJ Plauger

Dinkumware,Ltd。
http://www.dinkumware.com




" PJ Plauger" < pj*@dinkumware.com>在消息中写道

news:8D ***************** @nwrddc02.gnilink.net ...

"P.J. Plauger" <pj*@dinkumware.com> wrote in message
news:8D*****************@nwrddc02.gnilink.net...
"霍华德" <人***** @ hotmail.com>在消息中写道
新闻:Pc ********************* @ bgtnsc04-news.ops.worldnet.att.net ...
"Howard" <al*****@hotmail.com> wrote in message
news:Pc*********************@bgtnsc04-news.ops.worldnet.att.net...
" Mark A. Gibbs" < X _ ********* @ rogers.com_x>在消息中写道
新闻:vR ********** @ news04.bloor.is.net.cable.rogers .com ...
"Mark A. Gibbs" <x_*********@rogers.com_x> wrote in message
news:vR**********@news04.bloor.is.net.cable.rogers .com...
美好的一天, char_traits< char_type> :: eof()会让我得到eof,但我怎样才能安全地获得
并且始终如一生成一个不是eof的值?我应该使用
~char_traits< char_type> :: eof()? char_traits< char_type> :: int_type()?
char_traits< char_type> :: eof()+ 1?
Good day,

What is the safest way to get a non-end of file value?
char_traits<char_type>::eof() will get me eof, but how can I safely and consistently generate a value that is not eof? should i use
~char_traits<char_type>::eof()? char_traits<char_type>::int_type()?
char_traits<char_type>::eof() + 1?



while(!char_traits< char_type>: :not_eof(char_traits< char_type> :: int_type(rand


while(!char_traits<char_type>::not_eof(char_traits <char_type>::int_type(rand

())))?

mark

mark



我觉得你对eof()很困惑。它是一个函数,而不是一个值。

在流上调用eof()检查流是否已经从流中读取了之前的结尾。从流中读取时,读取
直到读取失败。然后你可以检查失败是由于到达
结束(如预期)还是由于某种意外失败(错误)。



I think you are confused about eof(). It is a function, not a value.

Calling eof() on a stream checks if the stream has reached the end by a
previous read from the stream. When reading from a stream, you read until reading fails. Then you can check if the failure was due to reaching the end (as expected) or due to some kind of unexpected failure (an error).


不要检查输入并测试它是否为eof值,也不要检查
非eof值,因为首先没有这样的值。
don''t check the input and test it for being an "eof value", nor a "non-eof value", because there is no such value in the first place.



我认为你对char_traits< char_type> :: eof()感到困惑。它没有检查文件结尾,在< stdio.h>中声明的feof函数也是如此。相反,它返回适合于char_type元素流的文件结束代码。你*检查你从流缓冲区获得的输入并测试它是否为eof值。



I think you are confused about char_traits<char_type>::eof(). It
doesn''t check for end-of-file, as does the feof function declared
in <stdio.h>. Rather, it returns the end-of-file code suitable
for a stream of char_type elements. You *do* check the input you
obtain from a stream buffer and test it for being an "eof value".




有趣。然后我接受了你读过的流你在哪里检查返回的值而不是使用std :: eof()?
?这些是什么样的b $ b流?当然不是一个实际的文件,对吧?我必须

承认我从未使用过正常文件读取以外的流,或者用于简单字符转换的

字符串流。



Interesting. I take it then that there are streams that you read where
you do check the value returned instead of using std::eof()? What kind of
streams would those be? Certainly not an actual file, right? I have to
admit I''ve never used a stream other than for normal file reading, or a
string stream for simple character conversions.

此外,在C ++中,〜符号不用作不。运营商。那个符号
Also, in C++, the ~ symbol is not used as a "not" operator. That symbol


用于表示析构函数。的!符号是合乎逻辑的。但是当我
used to denote a destructor. The ! symbol is logical not. But as I


之前声明


stated

时,它与eof()无关,它是一个函数,而不是
before, it has nothing to do with eof(), which is a function, not a



值。
此外,在C ++中,〜符号*也*用作不。运营商。该
符号用于表示按位反转。当应用于eof()返回的值时,它很可能会将其更改为不等于eof()的值


value.
Also, in C++ the ~ symbol is *also* used as a "not" operator. That
symbol is used to denote a bitwise inversion. When applied to the
value returned by eof(), it very likely will change it to a value
that does not compare equal to eof().




真。但是在这种情况下,任何非身份操作都可以,如果你想要的只是一个与返回的值不同的
。当你向OP指出时,正确的符号是!,如果你想知道什么时候

某些东西是不正确,在这种情况下是值是不是 eof()值。


-Howard



True. But in that case, any non-identity operation at all would suffice, if
all you wanted was a value different from whatever was returned. And as you
pointed out to the OP, the correct symbol is !, if you want to know when
something is "not true", in this case when a value is "not" the eof() value.

-Howard


这篇关于〜性状:: EOF()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆