chili
chili

Reputation: 676

Interfacing with a vector<char> as a stream using binary write() read()

I'm currently investigating portable, idiomatic, standard library-only C++ methods of writing binary data into a std::vector<char>. I would like to interface with the container in the same manner as I would any other binary ostream, using the write() function.

So far the only thing I have turned up is inheriting from std::basic_streambuf<>. Are there any better alternatives to this?

Upvotes: 2

Views: 172

Answers (1)

Jesse Good
Jesse Good

Reputation: 52365

You are correct, inheriting from std::basic_streambuf is the way to do it. Not sure if you are interested, but boost::iostreams and boost::interprocess have implemented this type of stuff already:

http://www.boost.org/doc/libs/1_64_0/libs/iostreams/doc/index.html http://www.boost.org/doc/libs/1_64_0/doc/html/interprocess/streams.html

Upvotes: 2

Related Questions