Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
bitset
bitset::bitset
bitset operators
member functions:
bitset::any
bitset::count
bitset::flip
bitset::none
bitset::operator[]
bitset::reset
bitset::set
bitset::size
bitset::test
bitset::to_string
bitset::to_ulong


bitset::flip

public member function
bitset<N>& flip ( );
bitset<N>& flip ( size_t pos );

Flip bits

The version with no parameters flips all the bits in the bitset, i.e. changes all 0s for 1s and all 1s for 0s.
The parameterized version, flips only the bit at position pos.

The unary operator~ performs the same operation as flip().

Parameters

pos
Order position of the bit whose value is flipped.
Order positions are counted from the rightmost bit, which is order position 0.
size_t is an unsigned integral type.

Return value

*this
If pos is not a valid bit position, out_of_range is thrown.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// bitset::flip
#include <iostream>
#include <string>
#include <bitset>
using namespace std;
int main ()
{
  bitset<4> mybits (string("0001"));
  cout << mybits.flip(2) << endl;     // 0101
  cout << mybits.flip() << endl;      // 1010
  return 0;
}


See also