swap (<string>)

두 문자열의 문자 배열 교환합니다.

template<class Traits, class Allocator>
   void swap(
      basic_string<CharType, Traits, Allocator>& _Left,
      basic_string<CharType, Traits, Allocator>& _Right
   );

매개 변수

  • _Left
    하나의 문자열 요소가 다른 문자열에는 스왑 될 수 있습니다.

  • _Right
    첫 번째 문자열을 교체 하는 요소가 다른 문자열입니다.

설명

템플릿 함수 실행 특수 멤버 함수 _왼쪽. 스왑(_오른쪽) 문자열의 경우는 보장 상수 복잡 합니다.

예제

// string_swap.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

int main( ) 
{
   using namespace std;
   // Declaring an object of type basic_string<char>
   string s1 ( "Tweedledee" );
   string s2 ( "Tweedledum" );
   cout << "Before swapping string s1 and s2:" << endl;
   cout << "The basic_string s1 = " << s1 << "." << endl;
   cout << "The basic_string s2 = " << s2 << "." << endl;

   swap ( s1 , s2 );
   cout << "\nAfter swapping string s1 and s2:" << endl;
   cout << "The basic_string s1 = " << s1 << "." << endl;
   cout << "The basic_string s2 = " << s2 << "." << endl;
}
  
  
  
  

요구 사항

헤더: <string>

네임 스페이스: std