Bitset

A bitset is an array whose each value is either 0 or 1.

The following code creates a bitset that contains 10 elements:

bitset<10> s; 
s[1] = 1; 
s[3] = 1; 
s[4] = 1; 
s[7] = 1; 
cout << s[4] << "\n"; // 1 
cout << s[5] << "\n"; // 0
 
// To reset to 0
s.reset();

Applications