std::basic_istream<CharT,Traits>::ignore (3) - Linux Manuals
std::basic_istream<CharT,Traits>::ignore: std::basic_istream<CharT,Traits>::ignore
Command to display std::basic_istream<CharT,Traits>::ignore
manual in Linux: $ man 3 std::basic_istream<CharT,Traits>::ignore
NAME
std::basic_istream<CharT,Traits>::ignore - std::basic_istream<CharT,Traits>::ignore
Synopsis
basic_istream& ignore( std::streamsize count = 1, int_type delim = Traits::eof() );
Extracts and discards characters from the input stream until and including delim.
ignore behaves as an UnformattedInputFunction. After constructing and checking the sentry object, it extracts characters from the stream and discards them until any one of the following conditions occurs:
* count characters were extracted. This test is disabled in the special case when count equals 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 c in the input sequence is delim, as determined by Traits::eq_int_type(Traits::to_int_type(c), delim). The delimiter character is extracted and discarded. This test is disabled if delim is Traits::eof()
Parameters
count - number of characters to extract
delim - delimiting character to stop the extraction at. It is also extracted.
Return value
*this
Exceptions
failure if an error occurred (the error state flag is not goodbit) and exceptions() is set to throw for that state.
If an internal operation throws an exception, it is caught and badbit is set. If exceptions() is set for badbit, the exception is rethrown.
Example
The following example uses ignore to skip over non-numeric input:
// Run this code
#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
See also
extracts characters
get (public member function)
extracts characters until the given character is found
getline (public member function)
Pages related to std::basic_istream<CharT,Traits>::ignore
- std::basic_istream<CharT,Traits>::basic_istream (3) - std::basic_istream<CharT,Traits>::basic_istream
- std::basic_istream<CharT,Traits>::gcount (3) - std::basic_istream<CharT,Traits>::gcount
- std::basic_istream<CharT,Traits>::get (3) - std::basic_istream<CharT,Traits>::get
- std::basic_istream<CharT,Traits>::getline (3) - std::basic_istream<CharT,Traits>::getline
- std::basic_istream<CharT,Traits>::operator= (3) - std::basic_istream<CharT,Traits>::operator=
- std::basic_istream<CharT,Traits>::operator>> (3) - std::basic_istream<CharT,Traits>::operator>>
- std::basic_istream<CharT,Traits>::peek (3) - std::basic_istream<CharT,Traits>::peek
- std::basic_istream<CharT,Traits>::putback (3) - std::basic_istream<CharT,Traits>::putback
- std::basic_istream<CharT,Traits>::read (3) - std::basic_istream<CharT,Traits>::read
- std::basic_istream<CharT,Traits>::readsome (3) - std::basic_istream<CharT,Traits>::readsome
- std::basic_istream<CharT,Traits>::seekg (3) - std::basic_istream<CharT,Traits>::seekg
- std::basic_istream<CharT,Traits>::sentry (3) - std::basic_istream<CharT,Traits>::sentry
- std::basic_istream<CharT,Traits>::swap (3) - std::basic_istream<CharT,Traits>::swap
- std::basic_istream<CharT,Traits>::sync (3) - std::basic_istream<CharT,Traits>::sync
- std::basic_istream<CharT,Traits>::tellg (3) - std::basic_istream<CharT,Traits>::tellg
- std::basic_istream<CharT,Traits>::unget (3) - std::basic_istream<CharT,Traits>::unget
- std::basic_istream<CharT,Traits>::~basic_istream (3) - std::basic_istream<CharT,Traits>::~basic_istream
- std::basic_istream (3) - std::basic_istream
- std::basic_istream_sentry (3)
- std::basic_istringstream (3) - std::basic_istringstream