다음을 통해 공유


bitset::bitset

개체의 클래스를 생성 bitset<N> 비트가 0 또는 일부 지정 된 값 또는 문자열의에서 문자에서 얻은 값을 초기화 합니다.

bitset( );
bitset(
   unsigned long long _Val
);
explicit bitset(
   const char * _CStr
); 
template< 
  class CharType, 
  class Traits, 
  class Allocator 
>
  explicit bitset(
    const basic_string< CharType, Traits, Allocator >& _Str,
    typename basic_string< 
      CharType, Traits, Allocator >::size_type _Pos = 0
  );
template<
  class CharType,
  class Traits,
  class Allocator 
>
 explicit bitset(
  const basic_string< CharType, Traits, Allocator >& _Str,
  typename basic_string<
    CharType, Traits, Allocator >::size_type _Pos,
  typename basic_string< 
    CharType, Traits, Allocator >::size_type _Count,
  CharType _Zero = CharType (’0’), 
  CharType _One  = CharType (’1’)
);

매개 변수

  • _Val
    2 자료 표현의 생성 중인 bitset에 비트가 초기화에 사용할 부호 없는 정수입니다.

  • _Str
    문자열의 0과 1 bitset 비트 값을 초기화 하는 데 사용 합니다.

  • _CStr
    C 스타일 문자열의 0과 1 bitset 비트 값을 초기화 하는 데 사용 합니다.

  • _Pos
    문자열에서 왼쪽에서 오른쪽으로 계산 하 고 0, bitset에 첫 번째 비트를 초기화 하는 데 시작 문자 위치입니다.

  • _Count
    Bitset 비트에 대 한 초기 값을 제공 하는 데 사용 되는 문자열의 문자 수입니다.

  • _Zero
    0을 나타내는 데 사용 되는 문자입니다.기본값은 '0'입니다.

  • _One
    나타내는 데 사용 되는 문자입니다.기본값은 '1'입니다.

설명

세 명의 생성자를 사용 obects 클래스를 만들려면 bitset<N>.

  • 첫 번째 생성자 매개 변수를 받아들이지, 클래스의 개체가 생성 bitset<N> 및 기본 값 N 비트가 모두 0으로 초기화 합니다.

  • 두 번째 생성자는 개체 클래스의 생성 bitset<N> 비트 단일 사용 하 여 초기화 하 고 unsigned long long 매개 변수.

  • 세 번째 생성자는 개체 클래스의 생성 bitset<N>, N 초기화 비트 c 스타일 문자열의 0과 1에서 제공 하는 문자에 해당 하는 값입니다.문자열을 문자열 형식으로 캐스팅 하지 않고도 생성자를 호출 합니다.bitset<5> b5("01011");

또한 두 생성자 템플릿이 제공 됩니다.

  • 클래스의 개체는 첫 번째 생성자 템플릿이 생성 bitset<N> 0과 1의 문자열에서 제공 하는 문자에서 비트를 초기화 합니다.문자열의 모든 문자를 0 또는 1이 아닌 경우 object 클래스의 생성자를 throw 인수가 잘못 되었습니다..위치를 지정 하는 경우 (_Pos) 생성자는 클래스의 개체를 throw 하 고 문자열의 길이 초과 된 out_of_range.생성자만 해당 비트 위치 설정 j 에 bitset입니다 문자 문자열 위치에서 _Pos + j 1입니다.기본적으로 _Pos 0입니다.

  • 생성자의 두 번째 템플릿은 첫 유사 하지만 추가 매개 변수가 포함 되어 있습니다 (_Count) 초기화 하는 비트 수를 지정 하려면 사용 됩니다.또한 두 개의 선택적 매개 변수가 있습니다 _Zero 및 _One를 나타내는 내용에 문자 _Str 0 비트는 1 비트를 각각 의미를 해석할 수 있습니다.

예제

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

int main( )
{
   // Using the default constructor
   using namespace std;
   bitset<2> b0;
   cout << "The set of bits in bitset<2> b0 is: ( "
        << b0 << " )." << endl;

   // Using the second member function
   bitset<5> b1 ( 6 );
   cout << "The set of bits in bitset<5> b1( 6 ) is: ( "
        << b1 << " )." << endl;

   // The template parameter N can be an expresssion
   bitset< 2 * sizeof ( int ) > b2;
   cout << "The set of bits in bitset<2 * sizeof ( int ) > b2 is: ( "
        << b2 << " )." << endl;

   // The base two representation will be truncated
   // if its length exceeds the size of the bitset
   bitset<3> b3 ( 6 );
   cout << "The set of bits in bitset<3> b3( 6 ) is ( "
        << b3 << " )." << endl;

   // Using a c-style string to initialize the bitset
    bitset<7> b3andahalf ( "1001001" );
    cout << "The set of bits in bitset<7> b3andahalf ( \"1001001\" )"
         << " is ( " << b3andahalf << " )." << endl; 

   // Using the fifth member function with the first parameter
   string bitval4 ( "10011" );
   bitset<5> b4 ( bitval4 );
   cout << "The set of bits in bitset<5> b4( bitval4 ) is ( "
        << b4 << " )." << endl;

   // Only part of the string may be used for initialization

   // Starting at position 3 for a length of 6 (100110)
   string bitval5 ("11110011011");
   bitset<6> b5 ( bitval5, 3, 6 );
   cout << "The set of bits in bitset<11> b5( bitval, 3, 6 ) is ( "
        << b5 << " )." << endl;

   // The bits not initialized with part of the string
   // will default to zero
   bitset<11> b6 ( bitval5, 3, 5 );
   cout << "The set of bits in bitset<11> b6( bitval5, 3, 5 ) is ( "
        << b6 << " )." << endl;

   // Starting at position 2 and continue to the end of the string
   bitset<9> b7 ( bitval5, 2 );
   cout << "The set of bits in bitset<9> b7( bitval, 2 ) is ( "
        << b7 << " )." << endl;
}
  
  
  
  
  
  
  
  

요구 사항

헤더: <bitset>

네임 스페이스: std

참고 항목

참조

bitset Class