C++ streams confusion: istreambuf_iterator vs istream_iterator?

IOstreams use streambufs to as their source / target of input / output. Effectively, the streambuf-family does all the work regarding IO and the IOstream-family is only used for formatting and to-string / from-string transformation. Now, istream_iterator takes a template argument that says what the unformatted string-sequence from the streambuf should be formatted as, like … Read more

Get an istream from a char*

Here’s a non-deprecated method found on the web, has you derive your own std::streambuf class, but easy and seems to work: #include <iostream> #include <istream> #include <streambuf> #include <string> struct membuf : std::streambuf { membuf(char* begin, char* end) { this->setg(begin, begin, end); } }; int main() { char buffer[] = “I’m a buffer with embedded … Read more