* This example shows how to put curl output inside a stream (a variable, for * example) */
| 21 | * example) |
| 22 | */ |
| 23 | int 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 | } |
nothing calls this directly
no test coverage detected