Save cURL content result into a string in C++

前端 未结 7 1887
鱼传尺愫
鱼传尺愫 2020-11-30 22:16
int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, \"http://www.google.com\");
    curl_         


        
7条回答
  •  执念已碎
    2020-11-30 22:49

    I use Joachim Isaksson's answer with a modern C++ adaptation of CURLOPT_WRITEFUNCTION.

    No nagging by the compiler for C-style casts.

    static auto WriteCallback(char* ptr, size_t size, size_t nmemb, void* userdata) -> size_t {
      static_cast(userdata)->append(ptr, size * nmemb);
      return size * nmemb;
    }
    

提交回复
热议问题