swap (<string>)
交換兩個字串的字元陣列。
template<class Traits, class Allocator>
void swap(
basic_string<CharType, Traits, Allocator>& _Left,
basic_string<CharType, Traits, Allocator>& _Right
);
參數
_Left
項目將切換與另一個字串中的字串。_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