title: C++ : How to detect duplicates in vector<string> and print ONE copy?
body: <p>I'm new to C++. I was wondering how I can find duplicate strings in a vector and print out ONE copy of the string. For example, if I had &lt;"cat", "dog", "dog", "bird",> it would print out cat, dog, bird. I have sorted my vector and am using the adjacent_find function and iterating through the vector (since I have to find if any word is duplicated). My code detects duplicates, but it only prints out the non-duplicates. I would like to alter it to print out all the non-duplicates and also just ONE of the duplicates, so all strings in the vector are printed out. Here is the code I have so far: </p>
  
  <pre><code>public: void print(vector&lt;string&gt; in) // print method for printing a vector and it's key
  { 
  
    sort(in.begin(), in.end()); // sort the vector alphabetically first
  
    vector&lt;string&gt;::iterator it; 
  
        for( it = in.begin(); it != in.end(); it++ ) // iterate through it
  
  
               if(adjacent_find(in.begin(), in.end()) == in.end()) // don't print duplicates
  
  
               cout &lt;&lt; *it&lt;&lt;endl; // and print out each string in the vector
  }
  </code></pre>