I've installed libcurl on ubuntu 20.4 and I've been playing around with it. I decidedly wanted to create a program that would write a file from the internet. So I wrote this.
#include <iostream>
#include <string>
#include <curl/curl.h>
#include <fstream>
#include <unistd.h>
int main() {
std::ofstream htmlFile("index.html");
auto curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/");
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
htmlFile <<curl_easy_perform(curl);
htmlFile.close();
}
return 0;
}
When I run this file I'm given my apache webserver html code through the console. But when looking at the file I want to write to there's just a zero.
I'm stumped, I've seen so many different ways to do this. I find it strange that the html is logged to the console, but all it does is return 0.