public member function
<istream>
istream& ignore ( streamsize n = 1, int delim = EOF );
Extract and discard characters
Extracts characters from the input sequence and discards them.
The extraction ends when
n characters have been extracted and discarded or when the character
delim is found, whichever comes first. In the latter case, the
delim character itself is also extracted.
Parameters
- n
- Maximum number of characters to extract (and ignore).
This is an integer value of type streamsize.
- delim
- Delimiting character.
Return Value
The function returns
*this.
Errors are signaled by modifying the internal state flags:
| flag | error |
| eofbit | The end of the source of characters is reached during its operations. |
| failbit | - |
| badbit | An error other than the above happened. |
Additionally, in any of these cases, if the appropriate flag has been set with member function
ios::exceptions, an exception of type
ios_base::failure is thrown.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
// istream ignore
#include <iostream>
using namespace std;
int main () {
char first, last;
cout << "Enter your first and last names: ";
first=cin.get();
cin.ignore(256,' ');
last=cin.get();
cout << "Your initials are " << first << last;
return 0;
}
|
This example ilustrates how after reading the first character with
get, the remaining input characters up to the next whitespace character are ignored.
Basic template member declarations
( basic_istream<charT,traits> )
1 2
|
typedef traits::int_type int_type;
basic_istream& ignore (streamsize n = 1, int_type delim = traits::eof() );
|
See also
- istream::peek
- Peek next character (public member function)
- istream::get
- Get unformatted data from stream (public member function)
- istream::getline
- Get line from stream (public member function)
- istream::read
- Read block of data (public member function)
- istream::readsome
- Read block of data available in the buffer (public member function)