set
语法:
1 2 |
?? bitset &set(); ?? bitset &set( size_t pos, bool val=1 ); |
set()函数设置bitset上所有的位为1,然后返回bitset。如果指定pos,那么只有pos上的位被设置。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
//源代码 ??? /** ????? *? @brief Sets every bit to true. ???? */ ???? bitset<_Nb>& ???? set() ???? { ?????? this->_M_do_set(); ?????? this->_M_do_sanitize(); ?????? return *this; ???? } ??? /** ????? *? @brief Sets a given bit to a particular value. ????? *? @param? position? The index of the bit. ????? *? @param? val? Either true or false, defaults to true. ????? *? @throw? std::out_of_range? If @a pos is bigger the size of the %set. ???? */ ???? bitset<_Nb>& ???? set(size_t __position, bool __val = true) ???? { ?????? if (__position >= _Nb) ???? __throw_out_of_range(__N("bitset::set")); ?????? return _Unchecked_set(__position, __val); ???? } |
测试代码:
测试结果:
10000010
设置所有位:11111111
10000010
设置第5位:10100010
请按任意键继续. . .