W.F*_*.F. 13 c++ move-semantics c++11 c++14
在c ++引用中,我没有看到std::stringstream构造函数接受rvalue引用std::string.是否有任何其他辅助函数将字符串移动到字符串流而没有开销,或者是否有一个特殊的原因来制定这样的限制?
Pet*_*eld 10
您将能够将字符串移动到 C++20 中的字符串流中。
构造函数支持移动语义:
std::string myString{ "..." };
std::stringstream myStream{ std::move(myString) };
Run Code Online (Sandbox Code Playgroud)
也可以在构建后通过调用来完成str():
std::string myString{ "..." };
std::stringstream myStream;
myStream.str(std::move(myString));
Run Code Online (Sandbox Code Playgroud)