std::basic_istream<CharT,Traits>::ignore

Extracts and discards characters from the input stream until and including delim.

# Declarations

basic_istream& ignore( std::streamsize count = 1, int_type delim = Traits::eof() );

# Parameters

# Return value

*this

# Example

#include <iostream>
#include <limits>
#include <sstream>
 
constexpr auto 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;
        else if (input.fail())
        {
            input.clear(); // unset failbit
            input.ignore(max_size, '\n'); // skip bad input
        }
        else
            std::cout << n << '\n';
    }
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 172C++98the type of count was misspecified as intcorrected to std::streamsize

# See also