bitset::set

将 bitset 的所有位到 1 位或设置指定的位置。到 1。

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

参数

  • _Pos
    位的位置在中设置的 bitset 赋值。

  • _Val
    将赋值为位的指定位置。

返回值

成员函数调用 bitset 的副本。

备注

第二个成员函数引发异常 out_of_range,如果指定的位置高于 bitset 的范围大。

示例

// 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;
}
  

要求

页眉: <bitset>

命名空间: std

请参见

参考

bitset 类