#include #include #include // provides ostream_iterator #include using namespace std; typedef vector > BeatleContainer; void main() { const int NO_BEATLES = 4; char* first_names[] = {"Paul", "John", "Richard", "George"}; char* surnames[] = {"McCartney", "Lennon", "Starkey", "Harrison"}; BeatleContainer beatles_names1(NO_BEATLES); BeatleContainer beatles_names2(NO_BEATLES); for(int i = 0; i < NO_BEATLES; i++) // copy from char* arrays to vectors, inserting elements in the process { copy(&first_names[i][0], &first_names[i][strlen(first_names[i])], inserter(beatles_names1[i], beatles_names1[i].begin())); copy(&surnames[i][0], &surnames[i][strlen(surnames[i])], inserter(beatles_names2[i], beatles_names2[i].begin())); } // ostream_iterator allows a range to be copied directly to standard output - see chapter on iterators copy(beatles_names1[0].begin(), beatles_names1[0].end(), ostream_iterator(cout)); // swapping is possible because the ranges are of equal size and their vector elements define operator = swap_ranges(beatles_names1.begin(), beatles_names1.end(), beatles_names2.begin()); copy(beatles_names1[0].begin(), beatles_names1[0].end(), ostream_iterator(cout)); }