Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179
Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803
Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179
Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
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
*/