Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy can't I use std::string with libcurl?
    text
    copied!<p>I'm trying to make a very simple program that request a few pages, here is my code so far:</p> <pre><code>string fUrl = "http://google.com/"; int main(int argc, char *argv[]) { CURL *curl; CURLcode res; curl = curl_easy_init(); if (curl) { char const* chFUrl = fUrl.c_str(); //char const chFUrl[] = "http://google.com/"; curl_easy_setopt(curl, CURLOPT_URL, chFUrl); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); res = curl_easy_perform(curl); if (res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); curl_easy_cleanup(curl); cout &lt;&lt; chFUrl &lt;&lt; endl; system("pause"); } return 0; } </code></pre> <p>Now, notice that I'm trying to passa fUrl.c_str() to curl, but nothing happens, it simply skip through the curl functions, print the url and pause.<br> If I comment out thar line, and uncomment the "char const chFUrl[]...", everything works just fine and curl output the html response to the terminal.</p> <p>When I run through the fUrl.c_str() and it doesn't work, nothing is printed to the console on VS. I have very little experience with C++, so any ideas is appreciated.</p> <p>--Edit: I just tested this code:</p> <pre><code>char const chFUrl[] = "http://google.com"; for (int i = 0; i &lt; sizeof(chFUrl); i++) { cout &lt;&lt; chFUrl[i] &lt;&lt; endl; } </code></pre> <p>And it output the whole url to the terminal, however, when I use this:</p> <pre><code>char const* chFUrl = fUrl.c_str(); for (int i = 0; i &lt; sizeof(chFUrl); i++) { cout &lt;&lt; chFUrl[i] &lt;&lt; endl; } </code></pre> <p>It only outputs "http", even tough if I cout chFUrl[4] I get the ":".</p>
 

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