fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. vector<string> textLines{"AAA", "AAA", "BBB", "CCC"};
  8.  
  9. int main()
  10. {
  11. sort(textLines.begin(), textLines.end());
  12.  
  13. vector<string> duplicates;
  14. auto iter = unique(textLines.begin(), textLines.end(), [&duplicates](auto& first, auto& second) -> bool {
  15. if (first == second)
  16. {
  17. duplicates.push_back(second);
  18. return true;
  19. }
  20.  
  21. return false;
  22. });
  23. textLines.resize(distance(textLines.begin(), iter));
  24.  
  25. std:: cout << "Filtered:" << std::endl;
  26. for (auto& t : textLines)
  27. {
  28. std::cout << t << std::endl;
  29. }
  30.  
  31. std:: cout << "Duplicates:" << std::endl;
  32. for (auto& t : duplicates)
  33. {
  34. std::cout << t << std::endl;
  35. }
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 4256KB
stdin
Standard input is empty
stdout
Filtered:
AAA
BBB
CCC
Duplicates:
AAA