public member function
<bitset>

std::bitset::size

size_t size() const;
constexpr size_t size() noexcept;
Return size
Returns the number of bits in the bitset.

This is the template parameter with which the bitset class is instantiated (template parameter N).

引數



返回值

The number of bits in the bitset.

size_t 是一個無符號整數型別。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// bitset::size
#include <iostream>       // std::cout
#include <bitset>         // std::bitset

int main ()
{
  std::bitset<8> foo;
  std::bitset<4> bar;

  std::cout << "foo.size() is " << foo.size() << '\n';
  std::cout << "bar.size() is " << bar.size() << '\n';

  return 0;
}

輸出

foo.size() is 8
bar.size() is 4


資料競爭

無 (編譯時常量)。

異常安全

無異常保證: 絕不丟擲異常。

另見