fork(27) download
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <iterator>
  5. struct BothAre
  6. {
  7. char c;
  8. BothAre(char r) : c(r) {}
  9. bool operator()(char l, char r) const
  10. {
  11. return r == c && l == c;
  12. }
  13. };
  14. int main()
  15. {
  16. std::string str = "I Like StackOverflow a lot";
  17. std::string::iterator i = unique(str.begin(), str.end(), BothAre(' '));
  18. std::copy(str.begin(), i, std::ostream_iterator<char>(std::cout, ""));
  19. std::cout << '\n';
  20. }
  21.  
Success #stdin #stdout 0s 2960KB
stdin
Standard input is empty
stdout
I Like StackOverflow a lot