T
TBass
Hi,
I'm moving a socket library I wrote from C to C++. In the C version, I
had to malloc char arrays to store incoming communication. My hope was
to use std::string in C++, but then I realized a problem.
While '\0' is a valid string terminator for text, for my purposes it
is a problem. My program regularly gets '\0' as a value (Modbus/RTU
and TCP pass register values as the actual values, not the ASCII
chart). That would be a problem with std::string, I would think, since
it would see the '\0' as the end of a character stream, while, in
actuality, it would be all over the string and not indicate the
termination of the stream.
My question is whether I can write a stream of bytes to std::string,
read the length, and be able to get the whole string back. I expect
that I wouldn't be able to use any of the string functions, but could
I at least get the number of bytes store and get those bytes back at a
later time?
Or should I try a different container?
Thanks in advance,
T
I'm moving a socket library I wrote from C to C++. In the C version, I
had to malloc char arrays to store incoming communication. My hope was
to use std::string in C++, but then I realized a problem.
While '\0' is a valid string terminator for text, for my purposes it
is a problem. My program regularly gets '\0' as a value (Modbus/RTU
and TCP pass register values as the actual values, not the ASCII
chart). That would be a problem with std::string, I would think, since
it would see the '\0' as the end of a character stream, while, in
actuality, it would be all over the string and not indicate the
termination of the stream.
My question is whether I can write a stream of bytes to std::string,
read the length, and be able to get the whole string back. I expect
that I wouldn't be able to use any of the string functions, but could
I at least get the number of bytes store and get those bytes back at a
later time?
Or should I try a different container?
Thanks in advance,
T