Udostępnij za pośrednictwem


bitset::bitset

Obiekt klasy bitset<N> i inicjuje bitów zero, lub niektórych określona wartość lub wartości uzyskanych z ciągu znaków.

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’)
);

Parametry

  • _Val
    Niepodpisane liczba całkowita, których reprezentację base dwóch służy do inicjowania bitów w bitset generowana.

  • _Str
    Ciąg zer i jedynek używane do inicjowania wartości bit bitset.

  • _CStr
    C styl ciąg zer i jedynek używane do inicjowania wartości bit bitset.

  • _Pos
    Pozycja znaku w ciągu, licząc od lewej do prawej i począwszy od zera, używane do inicjowania pierwszy bit w bitset.

  • _Count
    Liczba znaków w ciągu, który jest używany do dostarczania wartości początkowej dla bitów w bitset.

  • _Zero
    Znak używany do reprezentowania zero.Wartością domyślną jest "0".

  • _One
    Znak używany do reprezentowania jednego.Domyślnym jest '1'.

Uwagi

Konstruktory trzy służą do konstruowania obects klasy bitset<N>:

  • Konstruktor pierwszy akceptuje żadnych parametrów, tworzy obiekt klasy bitset<N> i inicjuje wszystkie n bitów domyślną wartość zero.

  • Drugi konstruktor konstrukcje obiekt klasy bitset<N> i inicjuje bity przy użyciu pojedynczego unsigned long long parametru.

  • Trzeci konstruktora konstrukcje obiekt klasy bitset<N>, inicjowanie n bity wartości, które odpowiadają znaków w ciągu c styl znaku zer i jedynek.Wywołanie konstruktora bez Rzutowanie na typ string ciąg:bitset<5> b5("01011");

Są również dwa konstruktora szablonów, pod warunkiem:

  • Pierwszy szablon konstruktora konstrukcje obiekt klasy bitset<N> i inicjuje bity od znaków w ciągu zer i jedynek.Jeśli wszystkie znaki ciągu niż 0 lub 1 konstruktora generuje obiekt klasy nieprawidłowy argument.Jeśli określony w pozycji (_Pos) jest poza długość ciągu, a następnie konstruktora generuje obiekt klasy out_of_range.Konstruktor ustawia tylko tych bitów w pozycji j w bitset, dla których znak w ciągu w pozycji _Pos + j 1.Domyślnie _Pos jest 0.

  • Drugi szablonu konstruktora jest podobne do pierwszego, ale zawiera dodatkowy parametr (_Count), służy do określania liczby bitów zainicjować.Posiada dwa parametry opcjonalne, _Zero i _One, które wskazują co znaków w _Str należy interpretować oznacza 0 bit i 1 bit, odpowiednio.

Przykład

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

Wymagania

Nagłówek: <bitset>

Obszar nazw: std

Zobacz też

Informacje

bitset Class