#include <string>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <vector>
#include <iostream>
using namespace std;

struct endl_whitespace : std::ctype<char> {
    static const mask* make_table()
    {
        static std::vector<mask> v(table_size, mask()); // blank classification table
        v['\n'] = space;  // endl will be classified as whitespace
        return &v[0];
    }
    endl_whitespace(std::size_t refs = 0) : ctype<char>(make_table(), false, refs) {}
};
string stringCleaner(const string &str)
{
    istringstream tempStr(str);
    tempStr.imbue(locale(tempStr.getloc(), new endl_whitespace));
    ostringstream cleanLine;
    unique_copy(istream_iterator<string>(tempStr),
                istream_iterator<string>(),
                ostream_iterator<string>(cleanLine, "\n"));
    return cleanLine.str();
}

int main()
{
    std::cout << stringCleaner("http://www aaa com\nhttp://www bbb com\n"
                               "http://www bbb com\nhttp://www ccc com\n"
                               "http://www ddd com\nhttp://www ddd com\n"
                               "http://www ddd com\nhttp://www ddd com\n"
                               "http://www eee com");
}
