tags:

views:

79

answers:

2

I have been successful in saving a webpage to memory using a structure. But is it possible do it using a class? I am having trouble accessing the write data function inside the class.

Since I am writing from my mobile, I am unable to insert code snippets.

+1  A: 

You can use a C++ object to manage the state of the curl request and receive data

class CurlRequest {
public:
    CurlRequest() {
        //...
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, this);
    }
    size_t write(void *ptr, size_t size, size_t nmemb) {
        //...
    }
private:
    CURL *curl;
    static size_t writefunc(void *ptr, size_t size, size_t nmemb, void *data) {
        CurlRequest* req = static_cast<CurlRequest*>(data);
        req->write(ptr, size, nmemb);
    }
};
Alexandre Jasmin
+1  A: 

Or use Urdl.

usta