Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
–
–
–
–
–
Since C++20 you can move a
string
into a
stringstream
:
cppreference
Old answer for pre-C++20:
I do not see a
std::stringstream
constructor accepting rvalue reference of
std::string
That's right. Even the
str
setter doesn't utilize move semantics, so moving a string into
stringstream
is not supported (not in the current standard, but hopefully in the next one).
–
You'll be able to move a string into a string-stream in C++20.
Move semantics are supported by the
constructor
:
std::string myString{ "..." };
std::stringstream myStream{ std::move(myString) };
It can also be done after construction by calling str()
:
std::string myString{ "..." };
std::stringstream myStream;
myStream.str(std::move(myString));
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.