C++ bitset operator[] 函数

C++ bitset operator[] 函数

C++ bitset 函数用于访问位集的任何索引处的值。

语法

boolean operator [] (int pos);
reference operator[] (int pos);

参数

pos :参数 index 指定要分配值的位置。

返回值

函数返回索引处的值。

示例1

#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<4> b;
b[1]=1;
b[2]=b[1];
cout<< "b :" << b;
return 0;
}

输出:

b :0110

示例2

#include <iostream>
#include <bitset>
using namespace std;

int main()
{
bitset<4> b(string("1001"));
b[1]=1;
b[2]=b[1];
cout<< "b :" << b;
return 0;
}

输出:

b :1111

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程