5

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
  • 1,935
  • 1
  • 12
  • 28

1 Answers1

14

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
  • 413,367
  • 61
  • 711
  • 904