std::basic_istream::ignore
From cppreference.com
< cpp | io | basic istream
| basic_istream& ignore( std::streamsize count = 1, int_type delim = Traits::eof() );
|
||
Extracts and discards characters from the input stream until and including delim.
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:
-
countcharacters were extracted (this test is disabled in the special case whencountequals std::numeric_limits<std::streamsize>::max()
- end of file conditions occurs in the input sequence (in which case the function calls setstate(eofbit)
- the next available character
cin the input sequence isdelimas determined by Traits::eq_int_type(Traits::to_int_type(c), delim). The delimiter character is extracted and discarded (this test is disabled ifdelimis Traits::eof())
Contents |
[edit] Parameters
| count | - | number of characters to extract |
| delim | - | delimiting character to stop the extraction at. It is also extracted. |
[edit] Return value
*this
[edit] Example
#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'; } }
Output:
1 2
[edit] See also
| extracts characters (public member function) |
|
| extracts characters until the given character is found (public member function) |
|