스왑 (C++ STL <열>)
두 문자열의 문자 배열을 교환합니다.
template<class Traits, class Allocator> void swap( basic_string<CharType, Traits, Allocator>& _Left, basic_string<CharType, Traits, Allocator>& _Right );
매개 변수
_Left
요소를 다른 문자열의 요소와 교환할 단일 문자열입니다._Right
요소가 첫 번째 문자열과 교환되는 다른 문자열입니다.
설명
템플릿 함수는 문자열에 대해 특수 멤버 함수인 _Left.swap(_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