Move the string out of a std::ostringstream

This is now possible with C++20, with syntax like:

const std::string s = std::move(ss).str();

This is possible because the std::ostringstream class now has a str() overload that is rvalue-ref qualified:

basic_string<charT, traits, Allocator> str() &&;  // since C++20

This was added in P0408, revision 7, which was adopted into C++20.

This is the exact approach suggested by @MarcGlisse in a prescient comment from October 2014.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)