无涯教程-C++ Bitset - size()函数

69 阅读1分钟

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() <<
; 
     cout << "size of bitset b1 : " << b1.size() <<
; 
   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 <<
; 
     cout << "size of bitset b1 : " << c <<
; 
   return 0;
}

输出:

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

参考链接

www.learnfk.com/c++/cpp-bit…