code: код выполнен до индивидуальных заданий

master
MakhnovGA 2 лет назад
Родитель 6e1d4011cf
Сommit b2f21d03de

@ -13,11 +13,10 @@
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
<Add directory="curl/include" />
<Add directory="C:/Users/gmack/OneDrive/Рабочий стол/lab01/lab_01/curl/include" />
</Compiler>
<Linker>
<Add library="libcurl.dll.a" />
<Add directory="curl/lib" />
<Add library="curl/lib/libcurl.dll.a" />
</Linker>
</Target>
<Target title="Release">

@ -10,7 +10,7 @@
1682341619 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram.h
<vector>
1684761978 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\main.cpp
1685882470 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\main.cpp
<math.h>
<iostream>
<conio.h>
@ -20,6 +20,8 @@
"svg.h"
"histogram_internal.h"
<curl/curl.h>
<sstream>
<string>
1681931523 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\text.h
<vector>

@ -2,24 +2,24 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="text.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="histogram.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="73" topLine="0" />
<Cursor1 position="167" topLine="0" />
</Cursor>
</File>
<File name="text.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="histogram_internal.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="211" topLine="0" />
<Cursor1 position="173" topLine="0" />
</Cursor>
</File>
<File name="svg.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="svg.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<Cursor>
<Cursor1 position="106" topLine="0" />
<Cursor1 position="980" topLine="0" />
</Cursor>
</File>
<File name="svg.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<File name="text.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="980" topLine="0" />
<Cursor1 position="73" topLine="0" />
</Cursor>
</File>
<File name="histogram.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -27,19 +27,19 @@
<Cursor1 position="1502" topLine="23" />
</Cursor>
</File>
<File name="histogram_internal.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="main.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="173" topLine="0" />
<Cursor1 position="725" topLine="7" />
</Cursor>
</File>
<File name="histogram.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="svg.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="167" topLine="0" />
<Cursor1 position="106" topLine="0" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="text.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="811" topLine="0" />
<Cursor1 position="211" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

@ -39,39 +39,31 @@ input_data(istream &tin, bool prompt){
size_t
write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
CURL* curl = curl_easy_init();
if(curl) {
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
res = curl_easy_perform(curl);
if(res != CURLE_OK){
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
exit(1);
}
curl_easy_cleanup(curl);
}
size_t data_size = item_size * item_count;
return 0;
size_t data_size = item_size * item_count;
stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
buffer->write(reinterpret_cast<const char*>(items), data_size);
return data_size;
}
Input
download(const string& address) {
stringstream buffer;
CURL* curl = curl_easy_init();
if(curl) {
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
res = curl_easy_perform(curl);
if(res != CURLE_OK){
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
exit(1);
}
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_cleanup(curl);
CURL *curl = curl_easy_init();
if(curl)
{
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
res = curl_easy_perform(curl);
if (res != CURLE_OK)
{
fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
exit(1);
}
curl_easy_cleanup(curl);
}
return input_data(buffer, false);
}

Загрузка…
Отмена
Сохранить