C++ bitset size()函数用于检查位集的大小。它返回位集中的位数。
int size();
它返回位集中的位数。
#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
#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
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)