ignore

Syntax:

    istream& istream::ignore( streamsize num=1, int delim=EOF );

The ignore() function is used with input streams. It reads and throws away characters until num characters have been read (where num defaults to 1) or until the character delim is read (where delim defaults to EOF). The ignore() function can sometimes be useful when using the getline() function together with the » operator. For example, if you read some input that is followed by a newline using the » operator, the newline will remain in the input as the next thing to be read. Since getline() will by default stop reading input when it reaches a newline, a subsequent call to getline() will return an empty string. In this case, the ignore() function could be called before getline() to “throw away” the newline.

Related Topics: get, getline