std::basic_istream::ignore
来自cppreference.com
< cpp | io | basic istream
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
basic_istream& ignore( std::streamsize count = 1, int_type delim = Traits::eof() ); |
||
提取物和丢弃从输入流中的字符,直到并包括
delim
.原文:
Extracts and discards characters from the input stream until and including
delim
.表现为
UnformattedInputFunction
。在建设和检查岗哨对象的,提取的字符从流中丢弃它们,直到发生以下任何一个条件原文:
Behaves as
UnformattedInputFunction
. After constructing and checking the sentry object, extracts characters from the stream and discards them until any one of the following conditions occurs:-
count
特征提取(本次测试是在特殊情况下禁用count
等于std::numeric_limits<std::streamsize>::max()原文:count
characters were extracted (this test is disabled in the special case whencount
equals std::numeric_limits<std::streamsize>::max()
- 文件结束条件发生输入序列中的(在这种情况下,该函数调用setstate(eofbit)原文:end of file conditions occurs in the input sequence (in which case the function calls setstate(eofbit)
-
c
输入序列中的下一个可用的字符。delim
Traits::eq_int_type(Traits::to_int_type(c), delim)。被提取出来并丢弃分隔符(本次测试被禁用,如果delim
Traits::eof())原文:the next available characterc
in the input sequence isdelim
as determined by Traits::eq_int_type(Traits::to_int_type(c), delim). The delimiter character is extracted and discarded (this test is disabled ifdelim
is Traits::eof())
目录 |
[编辑] 参数
count | - | 要提取的字符数
|
delim | - | 分隔符,停止提取的。它也被提取.
原文: delimiting character to stop the extraction at. It is also extracted. |
[编辑] 返回值
*this
[编辑] 示例
#include <iostream> #include <sstream> #include <limits> int main() { std::istringstream input("1\n" "some non-numeric input\n" "2\n"); for(;;) { int n; input >> n; if(input.eof() || input.bad()) break; else if(input.fail()) { input.clear(); // unset failbit input.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // skip bad input } else std::cout << n << '\n'; } }
输出:
1 2
[编辑] 另请参阅
提取字符 (公共成员函数) | |
提取字符,直到给定的字符被发现 原文: extracts characters until the given character is found (公共成员函数) |