C++ Bitset 庫 - operator>> 函式



描述

C++ 函式 std::bitset::operator>> 將 bitsetx插入到字元流os.

宣告

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

C++98

template<class charT, class traits, size_t N>
basic_ostream<charT, traits>&
operator<< (basic_ostream<charT,traits>& os, const bitset<N>& x);

C++11

template<class charT, class traits, size_t N>
basic_ostream<charT, traits>&
operator<< (basic_ostream<charT,traits>& os, const bitset<N>& x);

引數

  • os - 要寫入的字元流。

  • x - 要寫入的 bitset。

返回值

返回進行操作的字元流,即os.

異常

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

示例

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

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

using namespace std;

int main(void) {

   string s = "101010";
   istringstream stream(s);
   bitset<2> b1;
   bitset<6> b2;

   /* Store first 2 bits */
   stream >> b1;
   cout << "b1 = " << b1 << endl;

   /* Stores next 4 bits */
   stream >> b2;
   cout << "b2 = " << b2 << endl;

   return 0;
}

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

b1 = 10
b2 = 001010
bitset.htm
廣告