cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : bitset : set
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
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::set public member function
bitset<N>& set ( );
bitset<N>& set ( size_t pos, bool val = true );

Set bits

The version with no parameters sets (to 1) all the bits in the bitset.
The parameterized version, stores val as the new value for bit at position pos.

Parameters

pos
Order position of the bit whose value is modified.
Order positions are counted from the rightmost bit, which is order position 0.
size_t is an unsigned integral type.
val
Value to store in the bit (either true or false).

Return value

*this

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

Example

// bitset::set
#include <iostream>
#include <bitset>
using namespace std;

int main ()
{
  bitset<4> mybits;

  cout << mybits.set() << endl;       // 1111
  cout << mybits.set(2,0) << endl;    // 1011
  cout << mybits.set(2) << endl;      // 1111

  return 0;
}

See also

bitset::reset Reset bits (public member function)
bitset::flip Flip bits (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us