bitset::operator[]

Retourne une référence à un bit à une position spécifiée dans un bitset si le bitset est modifiable ; sinon, elle retourne la valeur du bit à la place.

bool operator[](
   size_t _Pos
) const;
reference operator[](
   size_t _Pos
);

Paramètres

  • _Pos
    La position la recherche du bit dans le bitset.

Notes

Lorsque vous compilez avec le _SECURE_SCL 1, une erreur d'exécution se produit si vous tentez d'accéder à un élément en dehors de les limites de bitset. Pour plus d'informations, consultez Itérateurs vérifiés.

Exemple

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

int main( )
{
   using namespace std;
   bool b;
   bitset<5> b1 ( 6 );
   cout << "The initialized bitset<5> b1( 2 ) is: ( "<< b1 << " )."
        << endl;

   int i;
   for ( i = 0 ; i <= 4 ; i++ )
   {
      b = b1[ i ];
      cout << "  The bit in position "
           << i << " is " << b << ".\n";
   }
}

Sortie

The initialized bitset<5> b1( 2 ) is: ( 00110 ).
  The bit in position 0 is 0.
  The bit in position 1 is 1.
  The bit in position 2 is 1.
  The bit in position 3 is 0.
  The bit in position 4 is 0.

Configuration requise

**En-tête :**bitset <de >

Espace de noms : std

Voir aussi

Référence

bitset, classe