[ create a new paste ] login | about

Link: http://codepad.org/8hV4qC6A    [ raw code | output | fork ]

sehe - C++, pasted on Jul 8:
#include <iostream>
#include <fstream>
#include <iterator>
#include <deque>
#include <vector>

using namespace std;

struct newlinesep: ctype<char>
{
    newlinesep(): ctype<char>(get_table()) {}

    static ctype_base::mask const* get_table()
    {
        static vector<ctype_base::mask> rc(ctype<char>::table_size,ctype_base::mask());
        rc['\r'] = rc['\n'] = ctype_base::space;
        return &rc[0];
    }
};

int main()
{
    deque<string> str_queue;

    ifstream ifs("t.cpp");
    ifs.imbue(locale(locale(), new newlinesep));
    copy(istream_iterator<string>(ifs), istream_iterator<string>(), back_inserter(str_queue));
    copy(str_queue.begin(), str_queue.end(), ostream_iterator<string>(cout, "\n"));
    return 0;
}


Output:
#include "prelude.h"
#include <iostream>
#include <fstream>
#include <iterator>
#include <deque>
#include <vector>
using namespace std;
struct newlinesep: ctype<char>
{
    newlinesep(): ctype<char>(get_table()) {}
    static ctype_base::mask const* get_table()
    {
        static vector<ctype_base::mask> rc(ctype<char>::table_size,ctype_base::mask());
        rc['\r'] = rc['\n'] = ctype_base::space;
        return &rc[0];
    }
};
int main()
{
    deque<string> str_queue;
    ifstream ifs("t.cpp");
    ifs.imbue(locale(locale(), new newlinesep));
    copy(istream_iterator<string>(ifs), istream_iterator<string>(), back_inserter(str_queue));
    copy(str_queue.begin(), str_queue.end(), ostream_iterator<string>(cout, "\n"));
    return 0;
}


Create a new paste based on this one


Comments: