operator>> (<bitset>)

Liest eine Zeichenfolge aus Bitzeichen in ein bitset.

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

Parameter

  • _Istr
    Die Zeichenfolge, die in den eingegeben wird in das bitset einzufügende Eingabestream.

  • _Right
    Das bitset, das die Bits im Eingabestream empfängt.

Rückgabewert

Die Vorlagenfunktion gibt die Zeichenfolge _Istr zurück.

Hinweise

Die Vorlagenfunktion überlädt operator>>, um im bitset _Right das Wert bitset (str) zu speichern, wo str ein Objekt des Typs basic_string<CharType, Traits, allocator<CharType> >& ist, das aus _Istr extrahiert wird.

Die Vorlagenfunktion extrahiert Elemente aus _Istr und fügt sie in das bitset bis ein:

  • Alle Bitelemente sind im Eingabestream extrahiert wurde und gespeichert wurde im bitset.

  • Das bitset wird mit Bits im Eingabestream aufgefüllt.

  • Ein Eingabeelement auftritt, das weder 0 weiterhin 1. ist.

Beispiel

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

Eingabe

10110
1011
10k10

Anforderungen

Header: <bitset>

Namespace: std