I know it is possible to initialize bitsets using an integer or a string of 0s and 1s as below:
bitset<8> myByte (string("01011000")); // initialize from string
Is there anyway to change value of a bitset using an string as above after initialization?
Something like
should do the trick.
Yes, the overloaded
bitset::[]
operator returns abitset::reference
type that allows you to access single bits as normal booleans, for example:You even have some other features:
Edit: there is not an overloaded
=
operator to change a single bit from a string (well it should be a character) but you can do it with:Or with:
Equivalent to: