_Find_first() function in C++ bitset with Examples
Last Updated :
22 Dec, 2022
The _Find_first() is a built-in function in C++ Bitset class which returns an integer that refers the position of first set bit in bitset. If there isn’t any set bit, _Find_first() will return the size of the bitset. Syntax:
iterator bitset._Find_first()
or
int bitset._Find_first()
Parameters: The function accepts no parameter. Return Value: The function returns an integer which refers to the position of first set bit in bitset. If there isn’t any set bit, _Find_first() will return the size of the bitset. Below is the illustration of the above function:
CPP
#include <bits/stdc++.h>
using namespace std;
#define M 32
int main()
{
bitset<M> bset;
bitset<M> bset1;
bset[5] = 1;
bset[10] = 1;
cout << "position of first set bit in bset\n";
cout << bset._Find_first() << "\n";
cout << "position of first set bit in bset1\n";
cout << bset1._Find_first() << "\n";
return 0;
}
|
Output:
position of first set bit in bset
5
position of first set bit in bset1
32
Reference: https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-3.4/bitset-source.html
Share your thoughts in the comments
Please Login to comment...