C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ operator[]

C++ operator[]函数

C++ 函数用于访问值到 的任何索引。

语法

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 
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4