6

I know you can't extract an std::string from an std::ostringstream without copying (Creating an input stream from constant memory).

But is it possible to get an std::string_view?

Ryan Burn
  • 2,126
  • 1
  • 14
  • 35

1 Answers1

15

String-streams are not required to store their data in a single contiguous array. string_view is of course a view into a contiguous string.

So no, what you want is not possible. Best wait till C++20, when we get move support into/outof string-streams.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982