C++ Bitset 中的 reset()函数

首页 / C++入门教程 / C++ Bitset 中的 reset()函数

C++位集reset()函数用于重置位集的所有位。如果将索引作为参数,它将重置该索引的位。

reset - 语法

reset();
reset(int index);

reset - 参数

index  - 它使用一个参数作为索引,但这不是强制性的。

reset - 返回值

此函数不返回任何值。

reset - 例子1

#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<4> b(string("1001"));
cout<< "before applying reset method : " << b <<'\n';
cout<< "after applying reset method : " <<b.reset();
return 0;
}

输出:

before applying reset method : 1001
after applying reset method : 0000

reset - 例子2

#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<4> b(string("1001"));
cout<< "before apllying reset method : " << b <<'\n';
cout<< "after apllying reset method : " <<b.reset(3) <<'\n';
cout<< "after apllying reset method : " <<b.reset(0);
return 0;
}

输出:

before applying reset method : 1001
after applying reset method : 0001
after applying reset method : 0000

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

AI技术内参 -〔洪亮劼〕

推荐系统三十六式 -〔刑无刀〕

深入拆解Tomcat & Jetty -〔李号双〕

Vim 实用技巧必知必会 -〔吴咏炜〕

分布式数据库30讲 -〔王磊〕

小马哥讲Spring AOP编程思想 -〔小马哥〕

手把手带你写一个Web框架 -〔叶剑峰〕

给程序员的写作课 -〔高磊〕

Midjourney入门实践课 -〔Jovi〕

好记忆不如烂笔头。留下您的足迹吧 :)