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

C++ bitset size()

C++ size()函数

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

语法

int 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 

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