Powereleven
Powereleven

Reputation: 329

How to save a curl download in a std::string?

I know I can call system("curl path-LJO") from a c++ program to download a file and save it in the current directory and then I can use the STL to save it to a std::string. But is there a way to save it directly in a std::string? I know abot https://github.com/curl/curl but I was wondering: is any specifier in the curl command that does that? If not, what would be the best way to approach this?

Upvotes: 0

Views: 394

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 596121

You need to use the libcurl library in your code. You can use the CURLOPT_READFUNCTION and CURLOPT_READDATA options to setup a callback that saves the received data directly to your std::string variable.

Upvotes: 5

Related Questions