1
// Using the swap
function to swap two strings.
2
#include <iostream>
3
using std::cout;
4
using std::endl;
5
6
#include <string>
7
using std::string;
8
9
int main()
10
{
11
string first( "one" );
12
string second( "two" );
13
14
// output strings
15
cout << "Before swap:\n first:
" << first << "\nsecond: " << second;
16
17
first.swap( second ); // swap strings
18
19
cout << "\n\nAfter swap:\n first:
" << first
20
<< "\nsecond: " <<
second << endl;
21
return 0;
22
} // end main
Before
swap:
first: one
second:
two
After
swap:
first: two
second:
one
|