What is the nearest equivalent in C++ to the Java ByteArrayOutputStream

A

Angus

Hello

I need to port some Java code and am wondering if there is a close
equivalent to ByteArrayOutputStream.

I have been looking at the STL iostream library but not quite sure what is
best to use.

Any help would be much appreciated.
 
V

Victor Bazarov

Angus said:
I need to port some Java code and am wondering if there is a close
equivalent to ByteArrayOutputStream.

I have been looking at the STL iostream library but not quite sure
what is best to use.

Any help would be much appreciated.

Any standard stream has 'write' member that takes a pointer to char,
which is probably what you want... What problem are you solving?

V
 
A

Angus

Victor Bazarov said:
Any standard stream has 'write' member that takes a pointer to char,
which is probably what you want... What problem are you solving?

V

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?
 
V

Victor Bazarov

Angus said:
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.

Ah... No such thing as "embedded control characters" in C++, AFAIK.
'char' and 'unsigned char' are just integral types with value ranges.
Do you know if that is the case? If not what to use?

No, it's not the case. It seems you just need 'basic_stringstream' with
'unsigned char' as its first argument:

std::basic_stringstream<unsigned char> mystream;

(if unsigned char [0..255] is the requirement, Java's 'byte' is actually
unsigned) or use std::stringstream if 'char' is fine; you may need to
cast to unsigned char later.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top