다음을 통해 공유


vector::swap

두 벡터의 요소를 교환합니다.

void swap(    vector<Type, Allocator>& _Right ); friend void swap(    vector<Type, Allocator >& _Left,    vector<Type, Allocator >& _Right );

매개 변수

  • _Right
    교환할 요소를 제공하는 벡터이거나, _Left 벡터와 요소를 교환할 벡터입니다.

  • _Left
    _Right 벡터와 요소를 교환할 벡터입니다.

예제

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

int main( )
{
   using namespace std;   
   vector <int> v1, v2;

   v1.push_back(1);
   v1.push_back(2);
   v1.push_back(3);

   v2.push_back(10);
   v2.push_back(20);

   cout << "The number of elements in v1 = " << v1.size( ) << endl;
   cout << "The number of elements in v2 = " << v2.size( ) << endl;
   cout << endl;

   v1.swap(v2);

   cout << "The number of elements in v1 = " << v1.size( ) << endl;
   cout << "The number of elements in v2 = " << v2.size( ) << endl;
}
  

요구 사항

헤더: <vector>

네임스페이스: std

참고 항목

참조

vector 클래스

표준 템플릿 라이브러리