C++/String/string swap — различия между версиями
Admin (обсуждение | вклад) м (1 версия: Импорт контента...) |
|
(нет различий)
|
Текущая версия на 10:25, 25 мая 2010
Using string.swap function to swap two strings
#include <iostream>
using std::cout;
using std::endl;
#include <string>
using std::string;
int main()
{
string first( "one" );
string second( "two" );
cout << "Before swap:\n first: " << first << "\nsecond: " << second;
first.swap( second ); // swap strings
cout << "\n\nAfter swap:\n first: " << first
<< "\nsecond: " << second << endl;
return 0;
}
/*
Before swap:
first: one
second: two
After swap:
first: two
second: one
*/