C++ 位集庫 - operator<< 函式



描述

C++ 函式std::bitset::operator<<最多提取N位自並將它們儲存到另一個位集中x.

宣告

以下是來自 std::bitset 標頭檔案的 std::bitset::operator<< 函式宣告。

C++98

template<class charT, class traits, size_t N>
basic_istream<charT, traits>&
operator>> (basic_istream<charT,traits>& is, bitset<N>& x);

C++11

template<class charT, class traits, size_t N>
basic_istream<charT, traits>&
operator>> (basic_istream<charT,traits>& is, bitset<N>& x);

引數

  • is − 讀取的字元流。

  • x − 要讀取的位集。

返回值

返回操作的字元流,即.

異常

如果發生異常,所有物件都保持有效狀態。

示例

以下示例顯示了 std::bitset::operator<< 函式的用法。

#include <iostream>
#include <bitset>
#include <sstream>

using namespace std;

int main(void) {

   string s = "1000";
   istringstream stream(s);
   bitset<2> b;

   /* Store first 2 bits */
   stream >> b;

   cout << "b = " << b << endl;

   return 0;
}

讓我們編譯並執行上述程式,這將產生以下結果:

b = 10
bitset.htm
廣告
© . All rights reserved.