MCPcopy Create free account
hub / github.com/JosephP91/curlcpp / main

Function main

test/output_variable.cpp:23–48  ·  view source on GitHub ↗

* This example shows how to put curl output inside a stream (a variable, for * example) */

Source from the content-addressed store, hash-verified

21 * example)
22 */
23int main() {
24 // Create a stringstream object
25 ostringstream str;
26 // Create a curl_ios object, passing the stream object.
27 curl_ios<ostringstream> writer(str);
28
29 // Pass the writer to the easy constructor and watch the content returned in that variable!
30 curl_easy easy(writer);
31 easy.add<CURLOPT_URL>("https://google.com");
32 easy.add<CURLOPT_FOLLOWLOCATION>(1L);
33
34 try {
35 easy.perform();
36
37 // Print the content of ostringstream.
38 cout<<str.str()<<endl;
39
40 } catch (curl_easy_exception &error) {
41 // If you want to print the last error.
42 std::cerr<<error.what()<<std::endl;
43
44 // If you want to print the entire error stack you can do
45 error.print_traceback();
46 }
47 return 0;
48}

Callers

nothing calls this directly

Calls 2

print_tracebackMethod · 0.80
performMethod · 0.45

Tested by

no test coverage detected