There can be the one more example on the iter_swap() function of the C++ language :
Code:
#include <iostream>
using std::ct;
using std::endl;
#include <algorithm>
#include <iterator>
int main()
{
int b[ 9 ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
std::ostreamiterator< int > otpt( ct, " " );
cout << "Array a contains:\n ";
std::copy( b, b + 9, otpt );
std::iter_swap( &b[ 0 ], &b[ 1 ] );
cout << "\n Array a after swapping b[0] and b[1] using iter_swap:\n ";
std::copy( b, b + 9, otpt );
cout << endl;
return 0;
}
Code:
Output :
Array b contains:
1 2 3 4 5 6 7 8 9
Array b after swapping b[0] and b[1] using iter_swap:
2 1 3 4 5 6 7 8 9
Bookmarks