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

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

技术教程推荐

Python核心技术与实战 -〔景霄〕

Electron开发实战 -〔邓耀龙〕

接口测试入门课 -〔陈磊〕

Serverless入门课 -〔蒲松洋(秦粤)〕

Linux内核技术实战课 -〔邵亚方〕

物联网开发实战 -〔郭朝斌〕

基于人因的用户体验设计课 -〔刘石〕

说透区块链 -〔自游〕

超级访谈:对话汤峥嵘 -〔汤峥嵘〕

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