Re: Feeding string into ostringstream only uses up to the first null?
On May 31, 12:38 am, "Alf P. Steinbach" <al...@start.no> wrote:
* Christopher:
On May 30, 10:18 am, coomberjo...@gmail.com wrote:
On May 30, 4:47 am, James Kanze <james.ka...@gmail.com> wrote:
On May 29, 11:36 pm, coomberjo...@gmail.com wrote:
I have a few std::strings that I am using to store raw binary
data, each of which may very well include null bytes at any
point or points.
As others have pointed out, that's probably a design error.
However...
I guess I don't understand why. Strings are designed to be able to
handle binary data, including nulls.
According to who?
You make an interesting point, in a certain sense[1].
Very much. I've yet to really figure out what std::string was
designed for: it doesn't really have much support for text
(despite its name), and as a more general data container, I
can't imagine a case where std::vector wouldn't be superior.
(I've been playing around with UTF-8 a lot lately, and I've
found that although the interface uses std::string, internally,
std::vector< Byte >, where Byte is a typedef for unsigned char,
works a lot better, most of the time.)
Of course, if you're talking more generally, the word "string"
is usually associated with text, and I wouldn't normally expect
a string to be able to handle binary data (although it should be
able to contain any character data, including that which
contains a '\0' character).
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34