次の方法で共有


vector<bool>::swap

Exchanges the elements of two vectors with Boolean elements.

void swap(
    vector<bool>& _Right
);
static void swap(
    reference _Left,
    reference _Right
);

Parameters

  • _Left
    The vector whose elements are to be exchanged with those of the vector _Right.

  • _Right
    The vector whose elements are to be exchanged with those of the vector _Left.

Example

// vector_bool_swap.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>

int main( )
{
   using namespace std; 
   _Bvector v1, v2;

   v1.push_back( 1 );
   v1.push_back( 1 );
   v2.push_back( 0 );
   v2.push_back( 0 );

   cout << "The vector v1 is: " << v1.front( ) << " " << v1.back( ) << endl;
   cout << "The vector v2 is: " << v2.front( ) << " " << v2.back( ) << endl;

   swap( v1,v2 );

   cout << "After swapping, vector v1 is: " << v1.front( ) << " " << v1.back( ) << endl;
   cout << "After swapping, vector v2 is: " << v2.front( ) << " " << v2.back( ) << endl;
}
The vector v1 is: 1 1
The vector v2 is: 0 0
After swapping, vector v1 is: 0 0
After swapping, vector v2 is: 1 1

Requirements

Header: <vector>

Namespace: std

See Also

Reference

vector Class

Standard Template Library

Other Resources

vector<bool> Members