Use unique_copy to copy elements in an array to list with back_inserter : back_inserter « STL Algorithms Helper « C++ Tutorial






#include <iostream>
#include <list>
#include <algorithm>
#include <string>

using namespace std;

int main( ) {
   string arrStr[5] = {"A", "B", "A", "D", "E"};

   list<string> lstStrDest;
   unique_copy(&arrStr[0], &arrStr[5], back_inserter(lstStrDest));

   for (list<string>::iterator p = lstStrDest.begin( );
        p != lstStrDest.end( ); ++p) {
      cout << *p << endl;
   }
}
A
B
A
D
E








32.5.back_inserter
32.5.1.Use back_insert_iterator to insert element into a vector
32.5.2.Use unique_copy to copy elements in an array to list with back_inserter