std::bitset::count
Aus cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
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.
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.
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.
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) |