943,015 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 304
  • C++ RSS
Sep 3rd, 2010
0

c++ and libcurl: fopen as a function cause an error

Expand Post »
Mingw shows
C++ Syntax (Toggle Plain Text)
  1. ----- CurlT ( MAIN GCC DEBUG DEBUG_FULL BLITZ WIN32 )
  2. curl.cpp
  3. C:\MyApps\CurlT\curl.cpp: In function 'void* getfile(std::string, char*)':
  4. C:\MyApps\CurlT\curl.cpp:39: warning: cannot pass objects of non-POD type 'struct std::string' through '...'; call will abort at runtime
  5. C:\MyApps\CurlT\curl.cpp: In function 'int main()':
  6. C:\MyApps\CurlT\curl.cpp:57: warning: deprecated conversion from string constant to 'char*'
  7. CurlT: 1 file(s) built in (0:01.68), 1688 msecs / file, duration = 1703 msecs, parallelization 0%
  8. Linking...
  9. C:\upp\out\MINGW.Debug.Debug_full\CurlT.exe (1324179 B) linked in (0:00.67)
  10.  
  11. OK. (0:02.40)
HELP ME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

c++ Syntax (Toggle Plain Text)
  1. #include <curl/curl.h>
  2. #include <curl/easy.h>
  3. #include <iostream>
  4. #include <stdio.h>
  5. #include <String>
  6. using namespace std;
  7. void funct(string, char*);
  8.  
  9. size_t my_write_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
  10. {
  11. return fwrite(ptr, size, nmemb, stream);
  12. }
  13.  
  14. size_t my_read_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
  15. {
  16. return fread(ptr, size, nmemb, stream);
  17. }
  18. int my_progress_func(string *te,
  19. double t,
  20. double d,
  21. double ultotal,
  22. double ulnow)
  23. {
  24. cout<<d*100.0/t<<endl;;
  25. return 0;
  26. }
  27.  
  28. void *getfile(string url, char *file)
  29. {
  30. CURL *curl;
  31. CURLcode res;
  32. FILE *outfile;
  33.  
  34. curl = curl_easy_init();
  35. if(curl)
  36. {
  37. outfile = fopen(file, "w");
  38.  
  39. curl_easy_setopt(curl, CURLOPT_URL, url);
  40. curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
  41. curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write_func);
  42. curl_easy_setopt(curl, CURLOPT_READFUNCTION, my_read_func);
  43. curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
  44. curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_progress_func);
  45.  
  46. res = curl_easy_perform(curl);
  47.  
  48. fclose(outfile);
  49. /* always cleanup */
  50. curl_easy_cleanup(curl);
  51. }
  52.  
  53. return NULL;
  54. }
  55.  
  56. int main(){
  57. getfile("http://www.bing.com", "f.out");
  58. }
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Rishikeshan is offline Offline
18 posts
since Aug 2010
Sep 4th, 2010
0
Re: c++ and libcurl: fopen as a function cause an error
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() );
Reputation Points: 1159
Solved Threads: 285
Posting Virtuoso
vijayan121 is offline Offline
1,606 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Reversing an array of chars (algorithm for this?)
Next Thread in C++ Forum Timeline: final project, last error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC