fork download
  1. #include <string>
  2. #include <algorithm>
  3. #include <iterator>
  4. #include <sstream>
  5. #include <vector>
  6. #include <iostream>
  7. using namespace std;
  8. class line {
  9. string data;
  10. public:
  11. operator string() const { return data; }
  12. bool operator==(const line& ln) const { return data == ln.data; }
  13. friend istream& operator>>(istream& is, line& ln) {
  14. return getline(is, ln.data);
  15. }
  16. };
  17.  
  18. string stringCleaner(const string &str)
  19. {
  20. istringstream tempStr(str);
  21. ostringstream cleanLine;
  22. unique_copy(istream_iterator<line>(tempStr),
  23. istream_iterator<line>(),
  24. ostream_iterator<string>(cleanLine, "\n"));
  25. return cleanLine.str();
  26. }
  27.  
  28. int main()
  29. {
  30. std::cout << stringCleaner("http://www aaa com\nhttp://www bbb com\n"
  31. "http://www bbb com\nhttp://www ccc com\n"
  32. "http://www ddd com\nhttp://www ddd com\n"
  33. "http://www ddd com\nhttp://www ddd com\n"
  34. "http://www eee com");
  35. }
  36.  
Success #stdin #stdout 0.02s 2864KB
stdin
Standard input is empty
stdout
http://www aaa com
http://www bbb com
http://www ccc com
http://www ddd com
http://www eee com