strstream

ostrstream interprets constant string as pointer

偶尔善良 提交于 2019-12-14 03:50:01
问题 I ran across this problem while cleaning up the debug macros of an old C/C++ application: We have a Tracer class inheriting from ostrstream (I know it's been deprecated since C++98, but this application was written in 1998!) which we use like this: Tracer() << "some" << " message" << " here"; Now if the first value in the chain is a constant string like above, the result of calling ostrstream::str() on the Tracer (which is done in the destructor, inserting the result into a queue) contains a

Converting strstream to sstream conflict about c_str()

蹲街弑〆低调 提交于 2019-12-04 06:02:08
问题 I have this code block as written with strstream . And I converted it to sstream as below. I'm not sure, but I think printStream->str() is returning a string object with a copy (temporary) of the contents in the stream buffer pointed by printStream , and then then you are invoking c_str() on it and getting a const char * , and then casting away the const-ness, and then returning the pointer outside the function scope. I think since its a temporary value you are getting back from printStream-

Why was std::strstream deprecated?

牧云@^-^@ 提交于 2019-11-27 03:54:56
I recently discovered that std::strstream has been deprecated in favor of std::stringstream . It's been a while since I've used it, but it did what I needed to do at the time, so was surprised to hear of its deprecation. My question is why was this decision made, and what benefits does std::stringstream provide that are absent from std::strstream ? The strstream returned a char * that was very difficult to manage, as nowhere was it stated how it had been allocated. It was thus impossible to know if you should delete it or call free() on it or do something else entirely. About the only really

Why was std::strstream deprecated?

你离开我真会死。 提交于 2019-11-26 10:57:17
问题 I recently discovered that std::strstream has been deprecated in favor of std::stringstream . It\'s been a while since I\'ve used it, but it did what I needed to do at the time, so was surprised to hear of its deprecation. My question is why was this decision made, and what benefits does std::stringstream provide that are absent from std::strstream ? 回答1: The strstream returned a char * that was very difficult to manage, as nowhere was it stated how it had been allocated. It was thus