다음을 통해 공유


basic_istream::operator>>

Calls a function on the input stream or reads formatted data from the input stream.

basic_istream& operator>>(
   basic_istream& (*_Pfn)(basic_istream&)
);
basic_istream& operator>>(
   ios_base& (*_Pfn)(ios_base&)
);
basic_istream& operator>>(
   basic_ios<Elem, Tr>& (*_Pfn)(basic_ios<Elem, Tr>&))
;
basic_istream& operator>>(
   basic_streambuf<Elem, Tr> *_Strbuf
);
basic_istream& operator>>(
   bool& _Val
);
basic_istream& operator>>(
   short& _Val
);
basic_istream& operator>>(
   unsigned short& _Val
);
basic_istream& operator>>(
   int& _Val
);
basic_istream& operator>>(
   unsigned int& _Val
);
basic_istream& operator>>(
   long& _Val
);
basic_istream& operator>>(
   unsigned long& _Val
);
basic_istream& operator>>(
   long long& _Val
);
basic_istream& operator>>(
   unsigned long long& _Val
);
basic_istream& operator>>(
   void *& _Val
);
basic_istream& operator>>(
   float& _Val
);
basic_istream& operator>>(
   double& _Val
);
basic_istream& operator>>(
   long double& _Val
);

매개 변수

  • _Pfn
    함수 포인터입니다.

  • _Strbuf
    An object of type stream_buf.

  • _Val
    The value to read from the stream.

반환 값

The stream (*this).

설명

The <istream> header also defines several global extraction operators. 자세한 내용은 operator>>(<istream>)을 참조하십시오.

The first member function ensures that an expression of the form istr >> ws calls ws(istr), and then returns *this. The second and third functions ensure that other manipulators, such as hex, behave similarly. The remaining functions constitute the formatted input functions.

The function:

basic_istream& operator>>(
    basic_streambuf<Elem, Tr> *_Strbuf);

extracts elements, if _Strbuf is not a null pointer, and inserts them in _Strbuf. Extraction stops on end of file. It also stops without extracting the element in question, if an insertion fails or throws an exception (which is caught but not rethrown). If the function extracts no elements, it calls setstate(failbit). In any case, the function returns *this.

The function:

basic_istream& operator>>(bool& _Val);

extracts a field and converts it to a Boolean value by calling use_facet <num_get<Elem, InIt>(getloc). get(InIt( rdbuf), Init(0), *this, getloc, _Val). Here, InIt is defined as istreambuf_iterator<Elem, Tr>. The function returns *this.

The functions:

basic_istream& operator>>(short& _Val);
basic_istream& operator>>(unsigned short& _Val);
basic_istream& operator>>(int& _Val);
basic_istream& operator>>(unsigned int& _Val);
basic_istream& operator>>(long& _Val);
basic_istream& operator>>(unsigned long& _Val);

basic_istream& operator>>(long long& _Val);
basic_istream& operator>>(unsigned long long& _Val);

basic_istream& operator>>(void *& _Val);

each extract a field and convert it to a numeric value by calling use_facet<num_get<Elem, InIt>(getloc). get(InIt( rdbuf), Init(0), *this, getloc, _Val). Here, InIt is defined as istreambuf_iterator<Elem, Tr>, and _Val has type long*,* unsigned long*,* or void * as needed.

If the converted value cannot be represented as the type of _Val, the function calls setstate(failbit). In any case, the function returns *this.

The functions:

basic_istream& operator>>(float& _Val);
basic_istream& operator>>(double& _Val);
basic_istream& operator>>(long double& _Val);

each extract a field and convert it to a numeric value by calling use_facet<num_get<Elem, InIt>(getloc). get(InIt( rdbuf), Init(0), *this, getloc, _Val). Here, InIt is defined as istreambuf_iterator<Elem, Tr>, and _Val has type double or long double as needed.

If the converted value cannot be represented as the type of _Val, the function calls setstate(failbit). In any case, it returns *this.

예제

// istream_basic_istream_op_is.cpp
// compile with: /EHsc
#include <iostream>

using namespace std;

ios_base& hex2( ios_base& ib ) 
{
   ib.unsetf( ios_base::dec );
   ib.setf( ios_base::hex );
   return ib;
}

basic_istream<char, char_traits<char> >& somefunc(basic_istream<char, char_traits<char> > &i)
{
   if ( i == cin ) 
   {
      cerr << "i is cin" << endl;
   }
   return i;
}

int main( ) 
{
   int i = 0;
   cin >> somefunc;
   cin >> i;
   cout << i << endl;
   cin >> hex2;
   cin >> i;
   cout << i << endl;
}

입력

10
10

샘플 출력

i is cin
10
10
10
16

요구 사항

Header: <istream>

네임스페이스: std

참고 항목

참조

basic_istream 클래스

operator>>(<istream>)

iostream 프로그래밍

iostreams 규칙