How to read text from internet with C++

2019-09-04 04:08发布

问题:

I trying get text data from internet with C++ but I couldn't find anything useful.

like python;

import urllib
data = urllib.urlopen("examplesite.com/data.txt").read()

回答1:

Take a look at libcurl. It is a C library, with C++ bindings.

The libcurl website includes a collection of examples in C, including one that copies a URL to a block of memory, getinmemory.c

For C++, the main page of the curlcpp binding at https://github.com/JosephP91/curlcpp shows an example of downloading a URL to a file.