如何将curl下载保存在std :: string中? [英] How to save a curl download in a std::string?
问题描述
我知道我可以从c ++程序调用system("curl path-LJO")下载文件并将其保存在当前目录中,然后可以使用STL将其保存到std :: string.但是有没有一种方法可以直接将其保存在std :: string中呢?我知道abot https://github.com/curl/curl ,但我想知道:是任何说明符在curl命令中可以吗?如果没有,那么解决这个问题的最佳方法是什么?
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?
推荐答案
您需要使用 libcurl 代码中的库.您可以使用 CURLOPT_READFUNCTION
和 CURLOPT_READDATA
选项来设置回调,该回调将接收到的数据直接保存到您的 std :: string
变量.
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.
这篇关于如何将curl下载保存在std :: string中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!