Compartilhar via


bitset::count

Retorna o número de bits definidos na seqüência de bit.

size_t count( ) const;

Valor de retorno

O número de bits definidos na seqüência de bit.

Exemplo

A o criar este exemplo com o sinalizador de /Wp64 ou em uma plataforma de 64 bits, o compilador que avisará C4267 será gerado.Para obter mais informações sobre este aviso, consulte C4267 de aviso (nível 3) do compilador.

// bitset_count.cpp
// compile with: /EHsc
#include <bitset>
#include <iostream>

int main( )
{
    using namespace std;

    bitset<5> b1(4);

    cout << "The collection of bits in the original bitset is: ( "
         << b1 << " )" << endl;

    size_t i;
    i = b1.count();
    cout << "The number of bits in the bitset set to 1 is: "
         << i << "." << endl;

    bitset<5> fb1;
    fb1 = b1.flip();

    cout << "The collection of flipped bits in the modified bitset "
         << "is: ( " << b1 << " )" << endl;

    size_t ii;
    ii = fb1.count();
    cout << "The number of bits in the bitset set to 1 is: "
         << ii << "." << endl;
}
  
  

Requisitos

Cabeçalho: <bitset>

namespace: STD

Consulte também

Referência

bitset Class