Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

operator>> (<istream>)

Extracts characters and strings from the stream.

template<class Elem, class Tr>
    basic_istream<Elem, Tr>& operator>>(
        basic_istream<Elem, Tr>& _Istr, 
        Elem *_Str
    );
template<class Elem, class Tr>
    basic_istream<Elem, Tr>& operator>>(
        basic_istream<Elem, Tr>& _Istr, 
        Elem& _Ch
    );
template<class Tr>
    basic_istream<char, Tr>& operator>>(
        basic_istream<char, Tr>& _Istr, 
        signed char *_Str
    );
template<class Tr>
    basic_istream<char, Tr>& operator>>(
        basic_istream<char, Tr>& _Istr, 
        signed char& _Ch
    );
template<class Tr>
    basic_istream<char, Tr>& operator>>(
        basic_istream<char, Tr>& _Istr, 
        unsigned char *_Str
    );
template<class Tr>
    basic_istream<char, Tr>& operator>>(
        basic_istream<char, Tr>& _Istr, 
        unsigned char& _Ch
    );
template<class Elem, class Tr, class Type>
    basic_istream<Elem, Tr>& operator>>(
        basic_istream<char, Tr>&& _Istr,
        Type& _Val
    );
_Ch

A character.

_Istr

A stream.

_Str

A string.

_Val

A type.

The stream

The basic_istream class also defines several extraction operators. For more information, see basic_istream::operator>>.

The template function:

template<class Elem, class Tr>
   basic_istream<Elem, Tr>& operator>>(
      basic_istream<Elem, Tr>& _Istr, Elem *_Str);

extracts up to N - 1 elements and stores them in the array starting at _Str. If _Istr.width is greater than zero, N is _Istr.width; otherwise, it is the size of the largest array of Elem that can be declared. The function always stores the value Elem() after any extracted elements it stores. Extraction stops early on end of file, on a character with value Elem(0) (which is not extracted), or on any element (which is not extracted) that would be discarded by ws. If the function extracts no elements, it calls _Istr.setstate(failbit). In any case, it calls _Istr.width(0) and returns _Istr.

Security Note   The null-terminated string being extracted from the input stream must not exceed the size of the destination buffer _Str. For more information, see Avoiding Buffer Overruns.

The template function:

template<class Elem, class Tr>
   basic_istream<Elem, Tr>& operator>>(
      basic_istream<Elem, Tr>& _Istr, Elem& _Ch);

extracts an element, if it is possible, and stores it in _Ch. Otherwise, it calls is.setstate(failbit). In any case, it returns _Istr.

The template function:

template<class Tr>
   basic_istream<char, Tr>& operator>>(
      basic_istream<char, Tr>& _Istr, signed char *_Str);

returns _Istr >> (char *)_Str.

The template function:

template<class Tr>
   basic_istream<char, Tr>& operator>>(
      basic_istream<char, Tr>& _Istr, signed char& _Ch);

returns _Istr >> (char&)_Ch.

The template function:

template<class Tr>
   basic_istream<char, Tr>& operator>>(
      basic_istream<char, Tr>& _Istr, unsigned char *_Str);

returns _Istr >> (char *)_Str.

The template function:

template<class Tr>
   basic_istream<char, Tr>& operator>>(
      basic_istream<char, Tr>& _Istr, unsigned char& _Ch);

returns _Istr >> (char&)_Ch.

The template function:

template<class Elem, class Tr, class Type>
   basic_istream<Elem, Tr>& operator>>(
      basic_istream<char, Tr>&& _Istr,
      Type& _Val
   );

returns _Istr >> _Val (and converts an rvalue reference to _Istr to an lvalue in the process).

// istream_op_extract.cpp
// compile with: /EHsc
#include <iostream>
using namespace std;

int main( ) 
{
   ws( cin );
   char c[10];

   cin.width( 9 );
   cin >> c;
   cout << c << endl;
}
1234567890
12345678

Header: <istream>

Namespace: std

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.