首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

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不对应于位集中的有效位置。

二次

代码语言:javascript
复制
#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";
    }
}

二次

产出:

二次

代码语言:javascript
复制
first set bit at index 4

二次

另见

operator[]

accesses specific bit (public member function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com