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

std::bitset::set

bitset<N>& set();

(1)

bitset<N>& set( size_t pos, bool value = true );

(2)

将所有位设置为true或特定的价值。

1%29将所有位设置为true...

2%29设置位在位置pos价值value...

参数

pos

-

the position of the bit to set (least significant to most significant)

value

-

the value to set the bit to

返回值

*this...

例外

1%29

(none)

(until C++11)

noexcept specification: noexcept

(since C++11)

2%29投std::out_of_range如果pos不对应于位集中的有效位置。

二次

代码语言:javascript
复制
#include <iostream>
#include <bitset>
 
int main()
{
    std::bitset<8> b;
    for (size_t i = 1; i < b.size(); i += 2) {
        b.set(i);
    }
    std::cout << b << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
10101010

二次

另见

reset

sets bits to false (public member function)

flip

toggles the values of bits (public member function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券