bitset::test

测试位在bitset中的指定位置是否设置为1。

bool test(
   size_t _Pos,
) const;

参数

  • _Pos
    位的位置在为其值将测试的bitset。

返回值

true,如果参数位置指定的位设置为1;否则,false

备注

成员函数引发。bitset的大小小于或等于在参数指定的位置 out_of_range 异常。

示例

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

int main( )
{
   using namespace std;

   bitset<5> b1 ( 6 );
   bool b;
   bitset<5>::element_type e;

   cout << "Original bitset b1(6) is: ( "<< b1 << " )"
        << endl;
   cout << "Note: positions in a bitset are numbered\n"
         << " from the right starting with 0.\n" << endl;

   b = b1.test ( 3 );

   if ( b )
      cout << "The bit at position 3 of bitset b1 "
           << "has a value of 1." << endl;
   else
      cout << "The bit at position 3 of bitset b1 "
           << "has a value of 0." << endl;

   b1[3] = 1;
   cout << "Bitset b1 modified by b1[3] = 1 is: ( "<< b1 << " )"
        << endl;
   
   e = b1.test ( 3 );
   if ( e )
      cout << "The bit at position 3 of bitset b1 "
           << "has a value of 1." << endl;
   else
      cout << "The bit at position 3 of bitset b1 "
           << "has a value of 0." << endl;
}
  
  
  

要求

标头: <bitset>

命名空间: std

请参见

参考

bitset Class