I have been struggling with this for some time now. This is my problem.

I have 2 sets of code, one that uses a function and another that uses a
class.

The set of code using a function works fine, but the code using the class is
not working, which is not good because I am trying to make my project in
class form.

My function code is attached as code 1.
My class code is attached as code 2.

I have also attached the error code that I got when I tried to compile code
2 using VS2010.

Please help me figure this out.
#include "curl/curl.h"
#include "curl/easy.h"

size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) 
{
        size_t written;
        written = fwrite(ptr, size, nmemb, stream);
        return written;
}

CURL *curl;
FILE *fp;
CURLcode res;
long lSize;
char *translated;

void func(){

        curl = curl_easy_init();

        if(curl) {
                fp = fopen("C:\\text1.txt","wb");
                curl_easy_setopt(curl, CURLOPT_URL, "http://www.cnn.com";);
                curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); 
                curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
                res = curl_easy_perform(curl);
                curl_easy_cleanup(curl);
                fclose(fp);
        }
}
#include "sourcefunc.h"

void func();

int main(){
        func();
        return 0;
}
#include <iostream>
#include <string>
#include "curl/curl.h"
#include "curl/easy.h"

using namespace std;

class rawdata
{
        size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) 
        {
                size_t written;
                written = fwrite(ptr, size, nmemb, stream);
                return written;
        }

private:
        
        CURL *curl;
        FILE *fp;
        CURLcode res;
        long lSize;
        char *translated;
        string data;

public:

        rawdata(string url); //constructor
        ~rawdata(); //destructor

        void read(); //read source
};

rawdata::rawdata(string url)
{
        string data = url;
}

rawdata::~rawdata(){};

void rawdata::read()
{
        curl = curl_easy_init();

        if(curl) {
                fp = fopen("C:\\text1.txt","wb");
                curl_easy_setopt(curl, CURLOPT_URL, data);
                curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); 
                curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
                res = curl_easy_perform(curl);
                curl_easy_cleanup(curl);
                fclose(fp);
        }
}
#include "sourceclass.h"

int main()
{
        rawdata cnn("http://www.cnn.com";);
        cnn.read();
        return 0;
}
1>------ Build started: Project: project2, Configuration: Debug Win32 ------
1>Build started 10/23/2010 12:27:08 AM.
1>InitializeBuildStatus:
1>  Creating "Debug\project2.unsuccessfulbuild" because "AlwaysCreate" was 
specified.
1>ClCompile:
1>  main.cpp
1>c:\project\libcurl\visualstudio\project2\project2\sourceclass.h(46): warning 
C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s 
instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help 
for details.
1>          C:\Program Files\Microsoft Visual Studio 
10.0\VC\include\stdio.h(234) : see declaration of 'fopen'
1>c:\project\libcurl\visualstudio\project2\project2\sourceclass.h(48): error 
C3867: 'rawdata::write_data': function call missing argument list; use 
'&rawdata::write_data' to create a pointer to member
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.87
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to