Compartir a través de


operator>> (<bitset>)

Lee una cadena de caracteres de bit en un bitset.

template<class CharType, class Traits, size_t Bits> 
   basic_istream<CharType, Traits>& operator>> ( 
      basic_istream<CharType, Traits>& _Istr,
      bitset<N>& _Right 
   );

Parámetros

  • _Istr
    La cadena especificada en el flujo de entrada en el bitset.

  • _Right
    El bitset que está recibiendo los bits del flujo de entrada.

Valor devuelto

La función de la plantilla devuelve la cadena _Istr.

Comentarios

La función de plantilla sobrecarga operador ?>> para almacenar en el _Right de bitset el bitset de valores (str), donde es un objeto str de basic_stringtipo<CharType, Rasgos, allocator<CharType> >& extraído de _Istr.

La función de plantilla extrae elementos de _Istr y los inserta en el bitset hasta:

  • Todos los elementos de bits han estado extraídos del flujo de entrada y se almacenan en el bitset.

  • El bitset se llena con los bits del flujo de entrada.

  • Se encuentra un elemento de entrada que no es 0 o 1.

Ejemplo

#include <bitset>
#include <iostream>
#include <string>

using namespace std;
int main()
{

   bitset<5> b1;
   cout << "Enter string of (0 or 1) bits for input into bitset<5>.\n"
        << "Try bit string of length less than or equal to 5,\n"
        << " (for example: 10110): ";
   cin >>  b1;

   cout << "The ordered set of bits entered from the "
        << "keyboard\n has been input into bitset<5> b1 as: ( "
        << b1 << " )" << endl;

   // Truncation due to longer string of bits than length of bitset
   bitset<2> b3;
   cout << "Enter string of bits (0 or 1) for input into bitset<2>.\n"
        << " Try bit string of length greater than 2,\n"
        << " (for example: 1011): ";
   cin >>  b3;

   cout << "The ordered set of bits entered from the "
        << "keyboard\n has been input into bitset<2> b3 as: ( "
        << b3 << " )" << endl;

   // Flushing the input stream
   char buf[100];
   cin.getline(&buf[0], 99);

   // Truncation with non-bit value
   bitset<5> b2;
   cout << "Enter a string for input into  bitset<5>.\n"
        << " that contains a character than is NOT a 0 or a 1,\n "
        << " (for example: 10k01): ";
   cin >>  b2;

   cout << "The string entered from the keyboard\n"
        << " has been input into bitset<5> b2 as: ( "
        << b2 << " )" << endl;
}

Entrada

10110
1011
10k10

Requisitos

bitset <deEncabezado: >

Espacio de nombres: std