title: Remove duplicate string elements C++
body: <p>The problem consists of finding all permutations using k out of n digits. I'm able to find all the permutations, but I'm struggling trying to erase duplicates. I can successfully compare and find the duplicates, but erasing them is what I'm struggling to do. I have a feeling I'm missing something simple but I don't know what it is.</p>
  
  <p>Any help would be greatly appreciated. I've been staring at this for a week.</p>
  
  <p>Here is the code that I've got right now.</p>
  
  <pre><code>void getPermutations(int n, int k)
  {
      string str = "";
  
      //fill string with numbers &lt;= n
      for(int i = 0; i &lt; n; i++)
      {
          str += to_string(i);  //convert numbers to string
      }
  
      string tempStr = "";
      string outputStr = "";
  
      do {
          tempStr = str.substr(0, k);
          int compareResult = tempStr.compare(0, k, outputStr, 0, k);
  
          if (compareResult == 0)
          {
              cout &lt;&lt; "| same | ";
              outputStr.erase(k,k);
  
          }
  
          outputStr = tempStr;
          cout &lt;&lt; outputStr &lt;&lt; " ";
      } while (next_permutation(str.begin(), str.end()));
  }
  </code></pre>