Namensräume
Varianten
Aktionen

std::bitset::count

Aus cppreference.com
< cpp‎ | utility‎ | bitset

 
 
 
std::bitset
Mitglied Typen
Original:
Member types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
bitset::reference
Member-Funktionen
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
bitset::bitset
bitset::operator==
bitset::operator!=
Elementzugriff zerstört
Original:
Element access
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
bitset::operator[]
bitset::test
bitset::all
bitset::any
bitset::none
(C++11)

 
bitset::count
Kapazität
Original:
Capacity
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
bitset::size
Modifiers
Original:
Modifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
bitset::operator&=
bitset::operator|=
bitset::operator^=
bitset::operator~
bitset::operator<<=
bitset::operator>>=
bitset::operator<<
bitset::operator>>
bitset::set
bitset::reset
bitset::flip
Conversions
Original:
Conversions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
bitset::to_string
bitset::to_ulong
bitset::to_ullong(C++11)
Non-Member-Funktionen
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
operator&
operator|
operator^
operator<<
operator>>
Helper-Klassen
Original:
Helper classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
std::hash(C++11)
 
size_t count() const;
Gibt die Anzahl der Bits, die true gesetzt werden .
Original:
Returns the number of bits that are set to true.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Inhaltsverzeichnis

[Bearbeiten] Parameter

(None)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten] Rückgabewert

Anzahl der Bits, die true gesetzt werden .
Original:
number of bits that are set to true.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten] Beispiel

#include <iostream>
#include <bitset>
 
int main()
{
    std::bitset<8> b("00010010");
    std::cout << "initial value: " << b << '\n';
 
    // find the first unset bit
    size_t idx = 0;
    while (idx < b.size() && b.test(idx)) ++idx;
 
    // continue setting bits until half the bitset is filled
    while (idx < b.size() && b.count() < b.size()/2) {
        b.set(idx);
        std::cout << "setting bit " << idx << ": " << b << '\n';
        while (idx < b.size() && b.test(idx)) ++idx;
    }
 
}

Output:

initial value: 00010010
setting bit 0: 00010011
setting bit 2: 00010111

[Bearbeiten] Siehe auch

gibt die Größe Anzahl von Bits, die bitset halten kann
Original:
returns the size number of bits that the bitset can hold
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(öffentliche Elementfunktion) [edit]