C++ Bitset 中的 size()函数

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

C++ bitset size()函数用于检查位集的大小。它返回位集中的位数。

size - 语法

int size();

size - 返回值

它返回位集中的位数。

size - 例子1

#include <iostream>
#include <bitset>
using namespace std;
int main()
{
    bitset<8> b;
    bitset<6> b1;
   cout << "size of bitset b : " << b.size() <<'\n'; 
     cout << "size of bitset b1 : " << b1.size() <<'\n'; 
   return 0;
}

输出:

size of bitset b : 8
size of bitset b1 : 6

size - 例子2

#include <iostream>
#include <bitset>
using namespace std;
int main()
{
    bitset<8> b(string("01010110"));
    bitset<4> b1(string("0110"));
      int a = b.size();
      int c = b1.size();
   cout << "size of bitset b : " << a <<'\n'; 
     cout << "size of bitset b1 : " << c <<'\n'; 
   return 0;
}

输出:

size of bitset b : 8
size of bitset b1 : 4

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

技术教程推荐

快速上手Kotlin开发 -〔张涛〕

Go语言核心36讲 -〔郝林〕

Linux性能优化实战 -〔倪朋飞〕

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

微信小程序全栈开发实战 -〔李艺〕

反爬虫兵法演绎20讲 -〔DS Hunter〕

手把手带你搭建推荐系统 -〔黄鸿波〕

AI大模型系统实战 -〔Tyler〕

徐昊 · AI 时代的软件工程 -〔徐昊〕

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