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

std::bitset::count

std::size_t count() const;

?

?

返回设置为true...

参数

%280%29

返回值

设置为true...

例外

(none)

(until C++11)

noexcept specification: noexcept

(since C++11)

二次

代码语言:javascript
复制
#include <iostream>
#include <bitset>
 
int main()
{
    std::bitset<8> b("00010010");
    std::cout << "initial value: " << b << '\n';
 
    // find the first unset bit
    size_t idx = 0;
    while (idx < b.size() && b.test(idx)) ++idx;
 
    // continue setting bits until half the bitset is filled
    while (idx < b.size() && b.count() < b.size()/2) {
        b.set(idx);
        std::cout << "setting bit " << idx << ": " << b << '\n';
        while (idx < b.size() && b.test(idx)) ++idx;
    }
 
}

二次

产出:

二次

代码语言:javascript
复制
initial value: 00010010
setting bit 0: 00010011
setting bit 2: 00010111

二次

另见

size

returns the size number of bits that the bitset can hold (public member function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com