C++ Bitset 库 - bitset() 函数
描述
C++ 构造函数std::bitset::bitset() 从 c 风格的字符串构造和初始化一个 bitset 容器。
声明
以下是 std::bitset::bitset() 构造函数形式 std::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 − 用于初始化位集的字符串。
n − str 中的字符数。
返回值
构造函数从不返回值。
异常
此成员函数从不抛出异常。
示例
以下示例显示了 std::bitset::bitset() 构造函数的用法。
#include <iostream>
#include <bitset>
using namespace std;
int main(void) {
const char *s = "1100";
bitset<4>b(s);
cout << b << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 −
1100

