std::bitset::bitset
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
| constexpr bitset() noexcept; |
(1) | |
| constexpr bitset( unsigned long long val ) noexcept; |
(2) | |
| template< class CharT, class Traits, class Allocator > explicit bitset( const std::basic_string<CharT,Traits,Allocator>& str, |
(3) | (至 C++11) (C++11 起) |
| template< class CharT > explicit bitset( const CharT* str, |
(4) | (C++11 起) |
val。如果N的bitset的大小和Mval设置位是多少,然后分(N,M)位将被包括在bitset的.val. If the N is the size of the bitset and M is the number of set bits in val, then only min(N, M) bits will be included in the bitset.str。可以提供一个可选的的起始位置pos和长度n,以及字符集(one)和取消(zero)位表示替代值. str. An optional starting position pos and length n can be provided, as well as characters denoting alternate values for set (one) and unset (zero) bits. n,str.size() - pos).n, str.size() - pos).pos > str.size(),该构造函数抛出std::out_of_range。如果任何字符检查strzero或one,它抛出std::invalid_argument.pos > str.size(), this constructor throws std::out_of_range. If any characters examined in str are not zero or one, it throws std::invalid_argument.CharT*std::basic_string.CharT* instead of a std::basic_string.目录 |
[编辑] 参数
| val | - | 数,用于初始化的bitset
原文: number used to initialize the bitset |
| str | - | 字符串,用于初始化bitset的
原文: string used to initialize the bitset |
| pos | - | 一开始偏移
str |
| n | - | 从
str要使用的字符数原文: number of characters to use from str |
| one | - | str中设置位的备选字符原文: alternate character for set bits in str |
| zero | - | 未设置位
str的备选字符原文: alternate character for unset bits in str |
[编辑] 例外
3. std::out_of_range if pos > str.size()
[编辑] 示例
#include <bitset> #include <string> int main() { // empty constructor std::bitset<8> b1; // [0,0,0,0,0,0,0,0] // unsigned long long constructor std::bitset<8> b2(42); // [0,0,1,0,1,0,1,0] // string constructor std::string bit_string = "110010"; std::bitset<8> b3(bit_string); // [0,0,1,1,0,0,1,0] std::bitset<8> b4(bit_string, 2); // [0,0,0,0,0,0,1,0] std::bitset<8> b5(bit_string, 2, 3); // [0,0,0,0,0,0,0,1] // string constructor using custom zero/one digits std::string alpha_bit_string = "aBaaBBaB"; std::bitset<8> b6(alpha_bit_string, 0, alpha_bit_string.size(), 'a', 'B'); // [0,1,0,0,1,1,0,1] // char* constructor using custom digits std::bitset<8> b7("XXXXYYYY", 0, 'X', 'Y'); // [0,0,0,0,1,1,1,1] return 0; }
[编辑] 另请参阅
| sets bits to true or given value (公共成员函数) | |
| 置位到false (公共成员函数) | |