C++ Bitset 庫 - bitset() 函式



描述

C++ 建構函式std::bitset::bitset()用於從 C 風格字串構造並初始化 bitset 容器。

宣告

以下是來自 std::bitset 標頭檔案的 std::bitset::bitset() 建構函式的宣告。

C++11

template <class charT>
explicit bitset (const charT* str,
                 typename basic_string<charT>::size_type n = basic_string<charT>::npos,
                 charT zero = charT('0'), charT one = charT('1')
                 );

引數

  • str − 用於初始化 bitset 的字串。

  • n − 來自str.

的字元數

返回值

建構函式從不返回值。

異常

此成員函式從不丟擲異常。

示例

#include <iostream>
#include <bitset>

using namespace std;

int main(void) {
   const char *s = "1100";

   bitset<4>b(s);

   cout << b << endl;

   return 0;
}

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

1100
bitset.htm
廣告