How do I convert from std::stringstream to std::string in C++?
Do I need to call a method on the string stream?
How do I convert from std::stringstream to std::string in C++?
Do I need to call a method on the string stream?
Use the .str()-method:
Manages the contents of the underlying string object.
1) Returns a copy of the underlying string as if by calling
rdbuf()->str().2) Replaces the contents of the underlying string as if by calling
rdbuf()->str(new_str)...Notes
The copy of the underlying string returned by str is a temporary object that will be destructed at the end of the expression, so directly calling
c_str()on the result ofstr()(for example inauto *ptr = out.str().c_str();) results in a dangling pointer...