curl WRITEFUNCTION和类 [英] curl WRITEFUNCTION and classes

查看:324
本文介绍了curl WRITEFUNCTION和类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class Filter{
private:
    string contents;
    bool Server(void);
public:
    void handle(void *, size_t, size_t, void *);
   };

我有一个类标题。我想调用curl WRITEFUNCTION里面的函数服务器,将使用句柄写入字符串内容。
虽然它保持giveng我的错误

i have a class header like this. i want to call curl WRITEFUNCTION inside the function Server which would use handle to write to the string contents. although it keeps giveng me the error

error: invalid use of member (did you forget the ‘&’ ?)

错误指向的行是CURLOPT_WRITEFUNCTION ....我的curl请求看起来像this ...

the line pointed by error is that of CURLOPT_WRITEFUNCTION.... My curl request looks something like this...

curl_easy_setopt(curl,CURLOPT_URL, address.c_str());
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,handle);
curl_easy_perform(curl);

这意味着它无法访问句柄?

that means its unable to access the handle().. how can i rectify this?

推荐答案

string temp;

curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,handle);
curl_easy_setopt(curl,CURLOPT_WRITEDATA,&temp);

size_t Filter::handle(void *ptr, size_t size, size_t nmemb, string stream)
{
    string temp(static_cast<const char*>(ptr), size * nmemb);
    stream = temp;
    return size*nmemb;
}

这是我如何让它工作..这将保存网站字符串命名为temp。

thats how i got it to work.. this will save the website to the string named temp.

这篇关于curl WRITEFUNCTION和类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆