code: вариант 9
Этот коммит содержится в:
26
main.cpp
26
main.cpp
@@ -46,12 +46,15 @@ size_t write_data(void* items, size_t item_size, size_t item_count, void* ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Input
|
Input
|
||||||
download(const string& address) {
|
download(const string& address)
|
||||||
|
{
|
||||||
stringstream buffer;
|
stringstream buffer;
|
||||||
CURL *curl = curl_easy_init();
|
CURL *curl = curl_easy_init();
|
||||||
if(curl)
|
if(curl)
|
||||||
{
|
{
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
|
curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
|
||||||
|
curl_version_info_data *version = curl_version_info(CURLVERSION_NOW);
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
||||||
@@ -61,9 +64,16 @@ stringstream buffer;
|
|||||||
fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
|
fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
curl_easy_cleanup(curl);
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr,"libcurl version %u.%u.%u\n",
|
||||||
|
(ver->version_num >> 16) & 0xff,
|
||||||
|
(ver->version_num >> 8) & 0xff,
|
||||||
|
ver->version_num & 0xff);
|
||||||
|
cerr << "OpenSSL version " << version->ssl_version << endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
return input_data(buffer, false);
|
return input_data(buffer, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,11 +81,15 @@ stringstream buffer;
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char* argv[]) {
|
main(int argc, char* argv[])
|
||||||
|
{
|
||||||
Input input;
|
Input input;
|
||||||
if (argc > 1) {
|
if (argc > 1)
|
||||||
|
{
|
||||||
input = download(argv[1]);
|
input = download(argv[1]);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
input = input_data(cin, true);
|
input = input_data(cin, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user