std::bitset::test
bool test( size_t pos ) const; | | |
|---|
返回位置处位的值。pos...
不像operator[],执行边界检查并抛出std::out_of_range如果pos不对应于位集中的有效位置。
参数
pos | - | position of the bit to return |
|---|
返回值
true如果设置了所请求的位,false否则。
例外
std::out_of_range如果pos不对应于位集中的有效位置。
例
二次
#include <iostream>
#include <bitset>
int main()
{
std::bitset<10> b1("1111010000");
size_t idx = 0;
while (idx < b1.size() && !b1.test(idx)) {
++idx;
}
if (idx < b1.size()) {
std::cout << "first set bit at index " << idx << '\n';
} else {
std::cout << "no set bits\n";
}
}二次
产出:
二次
first set bit at index 4二次
另见
operator[] | accesses specific bit (public member function) |
|---|
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

