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.  
  9. struct endl_whitespace : std::ctype<char> {
  10. static const mask* make_table()
  11. {
  12. static std::vector<mask> v(table_size, mask()); // blank classification table
  13. v['\n'] = space; // endl will be classified as whitespace
  14. return &v[0];
  15. }
  16. endl_whitespace(std::size_t refs = 0) : ctype<char>(make_table(), false, refs) {}
  17. };
  18. string stringCleaner(const string &str)
  19. {
  20. istringstream tempStr(str);
  21. tempStr.imbue(locale(tempStr.getloc(), new endl_whitespace));
  22. ostringstream cleanLine;
  23. unique_copy(istream_iterator<string>(tempStr),
  24. istream_iterator<string>(),
  25. ostream_iterator<string>(cleanLine, "\n"));
  26. return cleanLine.str();
  27. }
  28.  
  29. int main()
  30. {
  31. std::cout << stringCleaner("http://www aaa com\nhttp://www bbb com\n"
  32. "http://www bbb com\nhttp://www ccc com\n"
  33. "http://www ddd com\nhttp://www ddd com\n"
  34. "http://www ddd com\nhttp://www ddd com\n"
  35. "http://www eee com");
  36. }
  37.  
Success #stdin #stdout 0.02s 2868KB
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