| I/O manipulators | ||||
| Print functions(C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
| Synchronized Output | ||||
(C++20) | ||||
| Types | ||||
| Error category interface | ||||
(C++11) | ||||
(C++11) |
| Global objects | ||||
| Member functions | ||||
(C++11) | ||||
| Formatted input | ||||
| Unformatted input | ||||
basic_istream::ignore | ||||
| Positioning | ||||
| Miscellaneous | ||||
(C++11) | ||||
| Member classes | ||||
| Non-member functions | ||||
basic_istream& ignore(std::streamsize count=1, int_type delim= Traits::eof()); | ||
Extracts and discards characters from the input stream until and includingdelim.
ignore behaves as anUnformattedInputFunction. After constructing and checking the sentry object, it extracts characters from the stream and discards them until any of the following conditions occurs:
Contents |
| count | - | number of characters to extract |
| delim | - | delimiting character to stop the extraction at. It is also extracted |
*this
If an internal operation throws an exception, it is caught andbadbit is set. Ifexceptions() is set forbadbit, the exception is rethrown.
The following example usesignore to skip over non-numeric input:
#include <iostream>#include <limits>#include <sstream> constexprauto max_size=std::numeric_limits<std::streamsize>::max(); 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;elseif(input.fail()){ input.clear();// unset failbit input.ignore(max_size,'\n');// skip bad input}elsestd::cout<< n<<'\n';}}
Output:
12
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 172 | C++98 | the type ofcount was misspecified asint | corrected tostd::streamsize |
| extracts characters (public member function)[edit] | |
| extracts characters until the given character is found (public member function)[edit] |