Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You will have to use <a href="http://curl.haxx.se/libcurl/c/getinmemory.html" rel="noreferrer"><code>CURLOPT_WRITEFUNCTION</code></a> to set a callback for writing. I can't test to compile this right now, but the function should look something close to;</p> <pre><code>static std::string readBuffer; static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) { size_t realsize = size * nmemb; readBuffer.append(contents, realsize); return realsize; } </code></pre> <p>Then call it by doing;</p> <pre><code>readBuffer.clear(); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); // ...other curl options res = curl_easy_perform(curl); </code></pre> <p>After the call, <code>readBuffer</code>should have your contents.</p> <p>Edit: You can use <code>CURLOPT_WRITEDATA</code> to pass the buffer string instead of making it static. In this case I just made it static for simplicity. A good page to look (besides the linked example above) is <a href="http://curl.haxx.se/libcurl/c/curl_easy_setopt.html" rel="noreferrer">here</a> for an explanation of the options.</p> <p>Edit2: As requested, here's a complete working example without the static string buffer;</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;curl/curl.h&gt; static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) { ((std::string*)userp)-&gt;append((char*)contents, size * nmemb); return size * nmemb; } int main(void) { CURL *curl; CURLcode res; std::string readBuffer; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com"); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &amp;readBuffer); res = curl_easy_perform(curl); curl_easy_cleanup(curl); std::cout &lt;&lt; readBuffer &lt;&lt; std::endl; } return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload