Mingw shows

----- CurlT ( MAIN GCC DEBUG DEBUG_FULL BLITZ WIN32 )
curl.cpp
C:\MyApps\CurlT\curl.cpp: In function 'void* getfile(std::string, char*)':
C:\MyApps\CurlT\curl.cpp:39: warning: cannot pass objects of non-POD type 'struct std::string' through '...'; call will abort at runtime
C:\MyApps\CurlT\curl.cpp: In function 'int main()':
C:\MyApps\CurlT\curl.cpp:57: warning: deprecated conversion from string constant to 'char*'
CurlT: 1 file(s) built in (0:01.68), 1688 msecs / file, duration = 1703 msecs, parallelization 0%
Linking...
C:\upp\out\MINGW.Debug.Debug_full\CurlT.exe (1324179 B) linked in (0:00.67)

OK. (0:02.40)

HELP ME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#include <curl/curl.h>
#include <curl/easy.h>
#include <iostream>
#include <stdio.h>
#include <String>
using namespace std;
void funct(string, char*);

size_t my_write_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
  return fwrite(ptr, size, nmemb, stream);
}
 
size_t my_read_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
  return fread(ptr, size, nmemb, stream);
}
int my_progress_func(string *te,
                     double t, 
                     double d, 
                     double ultotal,
                     double ulnow)
{
  cout<<d*100.0/t<<endl;;
  return 0;
}

void *getfile(string url, char *file)
{
  CURL *curl;
  CURLcode res;
  FILE *outfile;
  
  curl = curl_easy_init();
  if(curl)
  {
    outfile = fopen(file, "w");
 
    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write_func);
    curl_easy_setopt(curl, CURLOPT_READFUNCTION, my_read_func);
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
    curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_progress_func);
 
    res = curl_easy_perform(curl);
 
    fclose(outfile);
    /* always cleanup */ 
    curl_easy_cleanup(curl);
  }
 
  return NULL;
}

int main(){
getfile("http://www.bing.com", "f.out");
}

Add a const qualifier to the string in void *getfile( string url, const char *file ); CUROPT_URL requires a c-style string for the url. curl_easy_setopt(curl, CURLOPT_URL, url.c_str() );

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.