Cpp-standard-library-cpp-bitset-operator-extraction

提供:Dev Guides
移動先:案内検索

C ++ビットセットライブラリ-operator <<関数

説明

C ++関数 *std
bitset :: operator <<* は、「+ is 」から最大「 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 -読み取られるビットセット。

戻り値

操作された文字ストリーム、つまり + is +

例外

例外が発生した場合、すべてのオブジェクトは有効な状態のままです。

次の例は、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