std::basic_istream::operator>>

From Cppreference

Jump to: navigation, search
basic_istream& operator>>( short& value );
basic_istream& operator>>( unsigned short& value );
(1)
basic_istream& operator>>( int& value );
basic_istream& operator>>( unsigned int& value );
(2)
basic_istream& operator>>( long& value );
basic_istream& operator>>( unsigned long& value );
(3)
basic_istream& operator>>( long long& value );
basic_istream& operator>>( unsigned long long& value );
(4) (C++11 feature)
basic_istream& operator>>( float& value );

basic_istream& operator>>( double& value );

basic_istream& operator>>( long double& value );
(5)
basic_istream& operator>>( bool& value );
(6)
basic_istream& operator>>( void*& value );
(7)
basic_istream& operator>>( CharT& ch );

basic_istream& operator>>( signed char& ch );

basic_istream& operator>>( unsigned char& ch );
(8) this operator is declared outside the class body
basic_istream& operator>>( CharT* s );

basic_istream& operator>>( signed char* s );

basic_istream& operator>>( unsigned char* s );
(9) this operator is declared outside the class body
basic_istream&

  operator>>( ios_base& (*func)(ios_base&) );
basic_istream&
  operator>>( basic_ios<CharT,Traits>& (*func)(basic_ios<CharT,Traits>&) );
basic_istream&

  operator>>( basic_istream& (*func)(basic_istream&) );
(10) this operator is declared outside the class body
basic_istream& operator>>( basic_streambuf<CharT,Traits>* sb );
(11) this operator is declared outside the class body

Extracts data from the stream.

The (1-8) versions of the operator behave as formatted input functions. That is, they construct a sentry object at the beginning that flushes the buffers if needed and checks for errors. The input is read only if the sentry object returns true.

1-4) Extracts an integer value

5) Extracts a floating point value

6) Extracts bool value

7) Extracts a generic pointer value

8) Extracts a character

9) Extracts a character string. The characters are extracted until a whitespace character is found.

10) Calls func(*this);

11) Extracts all data and stores it to sb. The extraction stops if one of the following conditions are met:

  • end-of-file occurs on the input sequence;
  • inserting in the output sequence fails (in which case the character to be inserted is not extracted);
  • an exception occurs (in which case the exception is caught).

Contents

[edit] Parameters

value - reference to an integer value to store the extracted value to
ch - reference to a character to store the extracted character to
s - pointer to a character string to store the extracted characters to
func - function to call
sb - pointer to the streambuffer to write all the data to

[edit] Return value

*this

[edit] Example

[edit] See also

read
extracts blocks of characters
(public member function)
readsome
extracts already available blocks of characters
(public member function)
get
extracts characters
(public member function)
getline
extracts characters until the given character is found
(public member function)