curl WRITEFUNCTION 和类
class Filter{
private:
string contents;
bool Server(void);
public:
void handle(void *, size_t, size_t, void *);
};
我有一个这样的类标题.我想在函数 Server 中调用 curl WRITEFUNCTION ,该函数将使用句柄写入字符串内容.虽然它一直给我错误
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 请求看起来像这样...
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);
这意味着它无法访问 handle()..我该如何纠正?
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.
相关文章