在IOStreams库中使用ignore(numeric_limits< streamsize> :: max())处理任意大量的流吗? [英] Does using ignore(numeric_limits<streamsize>::max()) in the IOStreams library handle arbitrarily massive streams?
问题描述
在C ++标准(第27.6.1.3 \24节)中,对于IOStreams库中的
istream ignore()
函数,你为 numeric_limits :: max()
的'n'提供参数,它将继续忽略字符
,直到找到分隔符,甚至超过streamize的实际
最大值(即'n'参数被解释为无限的)。
In the C++ standard (section 27.6.1.3\24), for the
istream ignore()
function in the IOStreams library, it implies that if you supply an argument for 'n' of numeric_limits::max()
, it will continue to ignore characters
forever up until the delimiter is found, even way beyond the actual
max value for streamsize (i.e. the 'n' argument is interpreted as infinite).
对于gcc实现,这确实看起来像是$实现了b $ b ignore()
,但是我仍然不清楚
是否是实现特定的,或者是标准强制的。
知道这一点的人是否确认这是由符合
标准的iostreams库保证的?
For the gcc implementation this does indeed appear to be how
ignore()
is implemented, but I'm still unclear as to
whether this is implementation specific, or mandated by the standard.
Can someone who knows this well confirm that this is guaranteed by a
standard compliant iostreams library?
推荐答案
标准规定 numeric_limits< streamsize> :: max()
是一个特殊值,不会影响跳过的字符数。
The standard says that numeric_limits<streamsize>::max()
is a special value that doesn't affect the number of characters skipped.
效果:作为一个未格式化的输入函数(如第27.7.2.3节第1段所述)。在构造哨兵对象之后,提取字符并丢弃它们。提取字符,直到发生以下任一情况:
- 如果n!= numeric_limits< streamsize> :: max()
(18.3.2) ,提取n个字符
- 输入序列上出现文件结束(在这种情况下,函数调用setstate(eofbit),可能会抛出ios_base :: failure(27.5.5.4));
- traits :: eq_int_type(traits :: to_int_type(c),delim)用于下一个可用的输入字符c(在这种情况下c被提取)。
Effects: Behaves as an unformatted input function (as described in 27.7.2.3, paragraph 1). After constructing a sentry object, extracts characters and discards them. Characters are extracted until any of the following occurs:
-- ifn != numeric_limits<streamsize>::max()
(18.3.2), n characters are extracted
-- end-of-file occurs on the input sequence (in which case the function calls setstate(eofbit), which may throw ios_base::failure (27.5.5.4));
-- traits::eq_int_type(traits::to_int_type(c), delim) for the next available input character c (in which case c is extracted).
这篇关于在IOStreams库中使用ignore(numeric_limits< streamsize> :: max())处理任意大量的流吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!