curl WRITEFUNCTION and classes(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.
这篇关于curl WRITEFUNCTION 和类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:curl WRITEFUNCTION 和类


基础教程推荐
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01