code: works with example
Этот коммит содержится в:
45
l03.cpp
45
l03.cpp
@@ -21,14 +21,18 @@ Input input_data(istream &in, bool promt)
|
|||||||
size_t number_count, bin_count;
|
size_t number_count, bin_count;
|
||||||
|
|
||||||
if (promt)
|
if (promt)
|
||||||
|
{
|
||||||
cerr << "Enter number count: ";
|
cerr << "Enter number count: ";
|
||||||
|
}
|
||||||
in >> number_count;
|
in >> number_count;
|
||||||
|
|
||||||
Input input;
|
Input input;
|
||||||
|
|
||||||
input.numbers.resize(number_count);
|
input.numbers.resize(number_count);
|
||||||
if (promt)
|
if (promt)
|
||||||
|
{
|
||||||
cerr << "Enter numbers: ";
|
cerr << "Enter numbers: ";
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < number_count; i++)
|
for (size_t i = 0; i < number_count; i++)
|
||||||
{
|
{
|
||||||
@@ -36,11 +40,25 @@ Input input_data(istream &in, bool promt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (promt)
|
if (promt)
|
||||||
|
{
|
||||||
cerr << "Count of baskets: ";
|
cerr << "Count of baskets: ";
|
||||||
|
}
|
||||||
in >> input.bin_count;
|
in >> input.bin_count;
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
size_t
|
||||||
|
write_data(void *items, size_t item_size, size_t item_count, void *ctx)
|
||||||
|
{
|
||||||
|
size_t data_size = item_count * item_size;
|
||||||
|
|
||||||
|
stringstream *buffer = reinterpret_cast<stringstream *>(ctx);
|
||||||
|
char *item = reinterpret_cast<char *>(items);
|
||||||
|
//(*buffer).write(item, data_size);
|
||||||
|
buffer->write(item, data_size);
|
||||||
|
|
||||||
|
return data_size;
|
||||||
|
}
|
||||||
|
|
||||||
Input download(const string &address)
|
Input download(const string &address)
|
||||||
{
|
{
|
||||||
@@ -55,16 +73,14 @@ Input download(const string &address)
|
|||||||
{
|
{
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
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_WRITEDATA, &buffer);
|
||||||
res = curl_easy_perform(curl);
|
res = curl_easy_perform(curl);
|
||||||
CURL *curl = curl_easy_init();
|
|
||||||
if (curl)
|
// res = curl_easy_perform(curl);
|
||||||
{
|
|
||||||
CURLcode res;
|
|
||||||
/* set options */
|
|
||||||
/* Perform the entire transfer */
|
|
||||||
res = curl_easy_perform(curl);
|
|
||||||
/* Check for errors */
|
|
||||||
if (res != CURLE_OK)
|
if (res != CURLE_OK)
|
||||||
|
{
|
||||||
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
||||||
curl_easy_strerror(res));
|
curl_easy_strerror(res));
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -75,12 +91,17 @@ Input download(const string &address)
|
|||||||
|
|
||||||
return input_data(buffer, false);
|
return input_data(buffer, false);
|
||||||
}
|
}
|
||||||
int
|
|
||||||
main(int argc, char* argv[]) {
|
|
||||||
|
int 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