Biblioteca basic_istream de C ++ - operador >>

Descripción

Este operador (>>) aplicado a un flujo de entrada se conoce como operador de extracción.

Declaración

A continuación se muestra la declaración para std :: basic_istream :: operator >>.

C ++ 98

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>> (float& val);
basic_istream& operator>> (double& val);
basic_istream& operator>> (long double& val);
basic_istream& operator>> (void*& val);
stream buffers (2)	
basic_istream& operator>> (basic_streambuf<char_type,traits_type>* sb );
manipulators (3)	
basic_istream& operator>> (basic_istream& (*pf)(basic_istream&));
basic_istream& operator>> (
  basic_ios<char_type,traits_type>& (*pf)(basic_ios<char_type,traits_type>&));
basic_istream& operator>> (ios_base& (*pf)(ios_base&));

C ++ 11

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>> (float& val);
basic_istream& operator>> (double& val);
basic_istream& operator>> (long double& val);
basic_istream& operator>> (void*& val);
stream buffers (2)	
basic_istream& operator>> (basic_streambuf<char_type,traits_type>* sb );
manipulators (3)	
basic_istream& operator>> (basic_istream& (*pf)(basic_istream&));
basic_istream& operator>> (
  basic_ios<char_type,traits_type>& (*pf)(basic_ios<char_type,traits_type>&));
basic_istream& operator>> (ios_base& (*pf)(ios_base&));

Parámetros

  • val - Es un objeto donde se almacena el valor que representan los caracteres extraídos.

  • sb - Puntero a un objeto basic_streambuf en cuya secuencia de salida controlada se copian los caracteres.

  • pf - Una función que toma y devuelve un objeto de flujo. Generalmente es una función de manipulador.

Valor devuelto

Devuelve el objeto basic_istream (* this).

Excepciones

Modifica val o el objeto señalado por sb y modifica el objeto de flujo.

Seguridad de excepción

Garantía básica: si se lanza una excepción, el objeto está en un estado válido.

Ejemplo

En el siguiente ejemplo para std :: basic_istream :: operator >>

#include <iostream>     

int main () {
   int n;

   std::cout << "Enter a number: ";
   std::cin >> n;
   std::cout << "You have entered: " << n << '\n';

   std::cout << "Enter a hexadecimal number: ";
   std::cin >> std::hex >> n;         
   std::cout << "Its decimal equivalent is: " << n << '\n';

   return 0;
}

Compilemos y ejecutemos el programa anterior, esto producirá el siguiente resultado:

Enter a number: 1
You have entered: 1
Enter a hexadecimal number: 5E
Its decimal equivalent is: 94