Export (0) Print
Expand All

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

Parameters

_Ch

A character.

_Istr

A stream.

_Str

A string.

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 beginning 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 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   Use a null-terminated string. The null-terminated string must not exceed the size of the destination buffer. 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, char& _Ch);

extracts an element, if 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.

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

Community Additions

ADD
Show:
© 2015 Microsoft