Udostępnij za pośrednictwem


bitset::set

Ustawia wszystkie bity bitset 1 lub ustawia bit w określonej pozycji 1.

bitset<N>& set( );
bitset<N>& set(
   size_t _Pos, 
   bool _Val = true
);

Parametry

  • _Pos
    Położenie w bitset, aby ustawić bit przypisaną wartość.

  • _Val
    Wartość ma być przypisany do pozycji określonej bit.

Wartość zwracana

Kopia bitset, dla którego został wywołany funkcji składowej.

Uwagi

Druga funkcja Członkowskie zgłasza out_of_range wyjątku, jeśli pozycja określona jest większy niż rozmiar bitset.

Przykład

// bitset_set.cpp
// compile with: /EHsc
#include <bitset>
#include <iostream>

int main( )
{
   using namespace std;

   bitset<5> b1 ( 6 );
   cout << "The set of bits in bitset<5> b1(6) is: ( "<< b1 << " )"
        << endl;

   bitset<5> b1s0;
   b1s0 = b1.set( 0 );
   cout << "The collecion of bits obtained from setting the\n"
        << " zeroth bit of bitset b1 is: ( "<< b1s0 << " )" 
        << endl;

   bitset<5> bs1;
   bs1 = b1.set( );
   cout << "The collecion of bits obtained from setting all the\n"
        << " elements of the bitset b1 is: ( "<< bs1 << " )"
        << endl;
}
  

Wymagania

Nagłówek: <bitset>

Obszar nazw: std

Zobacz też

Informacje

bitset Class