有什么方法可以在不复制的情况下从 std::ostringstream 中获取 std::string_view?
Any way to get an std::string_view from an std::ostringstream without copying?
我知道你不能在不复制的情况下从 std::ostringstream
中提取 std::string
(Creating an input stream from constant memory)。
但是有可能得到std::string_view
吗?
字符串流不需要将其数据存储在单个连续数组中。 string_view
当然是连续字符串的视图。
所以不,你想要的是不可能的。最好等到 C++20,当我们获得移动支持时 into/outof string-streams.
我知道你不能在不复制的情况下从 std::ostringstream
中提取 std::string
(Creating an input stream from constant memory)。
但是有可能得到std::string_view
吗?
字符串流不需要将其数据存储在单个连续数组中。 string_view
当然是连续字符串的视图。
所以不,你想要的是不可能的。最好等到 C++20,当我们获得移动支持时 into/outof string-streams.