Udostępnij za pośrednictwem


basic_istream::operator>>

Wywołuje funkcję strumienia wejściowego lub odczytuje sformatowane dane ze strumienia wejściowego.

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

Parametry

  • _Pfn
    Wskaźnik funkcji.

  • _Strbuf
    Obiekt typu stream_buf.

  • _Val
    Wartość do odczytu ze strumienia.

Wartość zwracana

Strumień (* to).

Uwagi

<istream> Nagłówka definiuje również kilka operatorów globalnego ekstrakcji.Aby uzyskać więcej informacji, zobacz operator>> (<istream>).

Pierwsza funkcja Członkowskie zapewnia, że wyrażenie postaci istr >> wswywołania ws(istr), a następnie zwraca * to.Funkcje drugiego i trzeciego zapewnienia innych manipulatory, takich jak hex, zachowują się podobnie.Pozostałe funkcje stanowią sformatowany funkcji wejściowych.

Funkcja:

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

wyodrębnia elementów, jeśli _Strbuf nie jest wskaźnik zerowy i wstawia je w _Strbuf.Ekstrakcja zatrzymuje się na koniec pliku.Również zatrzymuje bez wyodrębniania elementu w danym przypadku wstawiania awarii lub zgłasza wyjątek (która jest złowionych, ale nie rethrown).Jeśli funkcja ekstrakty żadnych elementów, wywołuje setstate(failbit).W każdym przypadku, funkcja zwraca * to.

Funkcja:

basic_istream& operator>>(bool& _Val);

pole wyodrębnia i konwertuje ją na wartość logiczną, wywołując use_facet <num_get<Elem, InIt> (getloc).get(InIt( rdbuf), Init(0), *this, getloc, _Val).W tym miejscu InIt jest zdefiniowana jako istreambuf_iterator<Elem, Tr>.Funkcja zwraca * to.

Funkcje:

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

Każda wyodrębnić pola i przekonwertować go na wartość liczbową, wywołując 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.

Jeśli typ nie może być reprezentowana konwertowaną wartość _Val, wywołania funkcji setstate(failbit).W każdym przypadku, funkcja zwraca * to.

Funkcje:

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

Każda wyodrębnić pola i przekonwertować go na wartość liczbową, wywołując 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.

Jeśli typ nie może być reprezentowana konwertowaną wartość _Val, wywołania funkcji setstate(failbit).W każdym przypadku zwraca * to.

Przykład

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

Dane wejściowe

10
10

Przykładowe dane wyjściowe

i is cin
10
10
10
16

Wymagania

Nagłówek: <istream>

Obszar nazw: std

Zobacz też

Informacje

basic_istream Class

operator>> (<istream>)

iostream Programowanie

iostreams Konwencji