Re: Looking for a byte stream class?
Angus wrote:
I need to port some Java code and am wondering if there is a close
equivalent to ByteArrayOutputStream.
I'm not exactly sure what that does, but if the only goal is bytewise output
to an array, using push_back with std::vector<uint8_t> (or possibly deque)
will do the job.
I have been looking at the STL iostream library but not quite sure what is
best to use.
FYI: STL!=C++ stdlib. Take a look at STL's homepage, somewhere on SGI's
website, the STL doesn't include any IOStreams.
Anyhow, IOStreams are still not really the best choice when you are dealing
with preformatted data, they expect to format the data themselves for which
they contain a locale and some formatting flags. Rather, you would use a
streambuffer, which is the part of an IOStream doing the actual IO.
Looking at a stringstream's streambuffer will show you that it basically is
only some gluecode writing into a string, so depending on your needs you
might as well use a string (or maybe rather a container of uint8_t) from
the beginning.
I am working with binary data - so bytes of anything. I am looking at
stringstream but maybe it won't like embedded control characters etc. Do
you know if that is the case? If not what to use?
You can embed null-bytes into strings with no problem, the only
interpretation that is done is that a char* is handled as null-terminated
string and that c_str() returns the content with an additional
null-character appended. However, problems typically arise with humans that
put some meaning into a string type object, i.e. that it contains text and
not some raw bytes.
Uli