Hello,
I usually use stringstream
to write into in-memory string. Is there a way to write to a char buffer in binary mode? Consider the following code:
stringstream s;
s << 1 << 2 << 3;
const char* ch = s.str().c_str();
The memory at ch
will look like this: 0x313233 - the ASCII codes of the characters 1, 2 and 3. I'm looking for a way to write the binary values themselves. That is, I want 0x010203 in the memory. The problem is that I want to be able to write a function
void f(ostream& os)
{
os << 1 << 2 << 3;
}
And decide outside what kind of stream to use. Something like this:
mycharstream c;
c << 1 << 2 << 3; // c.data == 0x313233;
mybinstream b;
b << 1 << 2 << 3; // b.data == 0x010203;
Any ideas?