Does using ignore(numeric_limits<streamsize>::max()) in the IOStreams library handle arbitrarily massive streams?

我们两清 提交于 2019-12-04 12:24:24
Bo Persson

The standard says that numeric_limits<streamsize>::max() is a special value that doesn't affect the number of characters skipped.

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:
-- if n != 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).

According to here:

istream&  istream::ignore ( streamsize n = 1, int delim = EOF );

Extract and discard characters Extracts characters from the input sequence and discards them.

The extraction ends when n characters have been extracted and discarded or when the character delim is found, whichever comes first. In the latter case, the delim character itself is also extracted.

In your case, when numeric_limits::max() number of characters have been reached, the first condition is met.

[Per Bo]

However, according to spec, the above case is applied only when n is not equal to numeric_limits<streamsize>::max().

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!