title: C++ CURL: treating header and body data differently
body: <p>I wish to write a C++ program to save the returned header to a variable and save the returned body to a text file. How can I do this?</p>
  
  <p>Currently, my approach is to overload the <code>handleData</code> function, but the compiler returns the error <code>overloaded function with no contextual type information</code>. This is what I have written so far (an extract of the code):</p>
  
  <pre><code>static size_t handleData(char *ptr, size_t size, size_t nmemb, string *str){ 
      string temp = string(ptr);
      // catch the cookie 
      if (temp.substr(0,10)=="Set-Cookie"){
         *str = temp;
      }
      return size * nmemb;
  }
  
  static size_t handleData(char *ptr, size_t size, size_t nmemb, FILE *stream){ 
      int written = fwrite(ptr, size, nmemb, stream);
      return written;
  }
  
  FILE *bodyfile;
  string *return_header = new string;
  
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, handleData); 
  curl_easy_setopt(curl, CURLOPT_HEADERDATA, return_header);
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, bodyfile);
  </code></pre>