Skip to content

Instantly share code, notes, and snippets.

@yangacer
Created August 16, 2011 17:33
Show Gist options
  • Save yangacer/1149630 to your computer and use it in GitHub Desktop.
Save yangacer/1149630 to your computer and use it in GitHub Desktop.
boost iostreams newline filter and array source
/**
* FreeBSD 8.2
* g++ -I /usr/local/include newline_array_src.cpp
**/
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/newline.hpp>
#include <boost/iostreams/device/array.hpp>
#include <string>
#include <cstring>
#include <iostream>
int main()
{
using namespace boost::iostreams;
using namespace std;
char const *text = "line1 abc\r\nline2 abc\r\n";
filtering_istream in;
in.push(newline_filter(newline::posix));
in.push(array_source(text, strlen(text)));
string line;
while(getline(in, line)){
cout<<line<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment