开发者

cURL in c++ using STL

开发者 https://www.devze.com 2023-02-15 19:50 出处:网络
the cURL example given here http://curl.haxx.se/libcurl/c/getinmemory.html shows how to get a url to memory. i would like to开发者_高级运维 change the above code to use in c++ without much change.

the cURL example given here

http://curl.haxx.se/libcurl/c/getinmemory.html

shows how to get a url to memory. i would like to开发者_高级运维 change the above code to use in c++ without much change. I would like to replace the malloc and realloc with something else. Is there a way to get the above code to work by using an STL like list or vector of strings to save the url to memory?


as nick has pointed out, luckyspin.org/?p=28 gave me the answer.

static int writer(char *data, size_t size, size_t nmemb,
                  std::string *buffer)
{
  int result = 0;

  if (buffer != NULL){
    buffer->append(data, size * nmemb);
    result = size * nmemb;
  }

  return result;
}


If you use C++, you can try curlpp : see this question : How do you make a HTTP request with C++?

my2c

0

精彩评论

暂无评论...
验证码 换一张
取 消