共用方式為


operator>> (<bitset>)

讀取位元組字元字串。bitset。

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

參數

  • _Istr
    輸入要插入的輸入資料流中 bitset 的字串。

  • _Right
    從輸入資料流接收的位元 bitset。

傳回值

樣板函式傳回字串 _Istr。

備註

樣板函式在 bitset _Right 多載 operator>> 儲存值 bitset (str),其中 str 是型別 basic_string<CharTypeTraitsallocator<CharType>物件>從 _Istr擷取的**&** 。

樣板函式擷取 _Istr 的項目並將這些內容插入 bitset 直到:

  • 所有位元項目從輸入資料流。bitset 擷取並儲存至。

  • bitset 以位元填滿從輸入資料流。

  • 不是介於 0 和 1. 的輸入遇到項目。

範例

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

輸入

10110
1011
10k10

需求

標題: <bitset>

命名空間: std