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 和类


基础教程推荐
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01