What is the difference between the following
stringstream a;
stringstream b;
a << "hi";
b << "there";
a << " " << b.rdbuf(); or a << " " << b.str(); or a << " " << b.str().c_str();
I’ve been using rdbuf(). I did notice that the C++ Reference says for stringstream::rdbuf:
Notice that for any successfully constructed istringstream object this
pointer is never NULL, even if the buffer string is empty.
I take that to mean rdbuf() will not return NULL? I can’t pass NULL. I’ve had faults like this char *array = NULL; a << array;. If the stringstream b is empty then is the behavior defined when doing a << b.rdbuf() << "some text"? Wouldn’t in that case the first character returned by rdbuf have eof traits, and therefore nothing in b would be appended?
Thanks
They are all equivalent in effect, but they may differ in performance or efficiency.
You take it correctly.
Yes.
No. The first call to
.sgetc()(or.snextc()) would not return a character with eof traits, it would return EOF (which is not a character). So, your example would be equivalent toa << "" << "some text".