Mega Code Archive

 
Categories / C++ / Algorithm
 

Use unique_copy to copy elements in an array to list with back_inserter

#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  */