3

I was coding with CppRESTsdk and got Concurrency::streams::istream from the response body like the following code:

web::http::http_response localVarResponse;
auto concurrencyStream = localVarResponse.body();

I want to convert the stream to std::istream and use it inside std::shared_ptr so that I can pass it to other classes like this:

std::istream stdStream = concurrencyStream;
auto istream_ptr = std::make_shared<std::istream>(stdStream);   

But I got errors:

 E0312  no suitable user-defined conversion from 
    "Concurrency::streams::istream" to "std::istream" exists

How can I convert to std::istream?

EDIT: indirectly via std::streambuf it works.

std::string str = localVarResponse.content_ready().get().extract_utf8string(true).get();
std::istringstream SStream(str);
std::istream inputStream(SStream.rdbuf());
user5005768Himadree
  • 1,375
  • 3
  • 23
  • 61
  • 1
    It might help if you share the errors that you get. `I get errors` is not very informative. – john Mar 31 '20 at 06:06
  • 3
    Looking at the documentation the types are unrelated. Therefore the only possible technique would be to write a `std::streambuf` derived class to forward requests to a contained concurrency::stream stream buffer. For example see here https://stackoverflow.com/questions/14086417/how-to-write-custom-input-stream-in-c, although google will show many more tutorials, this is a common topic. – john Mar 31 '20 at 06:13

0 Answers0