cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : istream : ignore
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
IOstream Library
manipulators
classes:
· filebuf
· fstream
· ifstream
· ios
· iostream
· ios_base
· istream
· istringstream
· ofstream
· ostream
· ostringstream
· streambuf
· stringbuf
· stringstream
objects:
· cerr
· cin
· clog
· cout
types:
· fpos
· streamoff
· streampos
· streamsize
istream
· istream::istream
· istream::~istream
member classes:
· istream::sentry
member functions:
· istream::gcount
· istream::get
· istream::getline
· istream::ignore
· istream::operator>>
· istream::peek
· istream::putback
· istream::read
· istream::readsome
· istream::seekg
· istream::sync
· istream::tellg
· istream::unget

-

istream::ignore public member functions
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:

flagerror
eofbitThe end of the source of characters is reached during its operations.
failbit-
badbitAn error other than the above happened.

Additionaly, 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

// 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> )
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)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us