code: works with example
Этот коммит содержится в:
51
l03.cpp
51
l03.cpp
@@ -21,14 +21,18 @@ Input input_data(istream &in, bool promt)
|
||||
size_t number_count, bin_count;
|
||||
|
||||
if (promt)
|
||||
{
|
||||
cerr << "Enter number count: ";
|
||||
}
|
||||
in >> number_count;
|
||||
|
||||
Input input;
|
||||
|
||||
input.numbers.resize(number_count);
|
||||
if (promt)
|
||||
{
|
||||
cerr << "Enter numbers: ";
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < number_count; i++)
|
||||
{
|
||||
@@ -36,17 +40,31 @@ Input input_data(istream &in, bool promt)
|
||||
}
|
||||
|
||||
if (promt)
|
||||
{
|
||||
cerr << "Count of baskets: ";
|
||||
}
|
||||
in >> input.bin_count;
|
||||
|
||||
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)
|
||||
{
|
||||
stringstream buffer;
|
||||
|
||||
//address.c_str();
|
||||
// address.c_str();
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
{
|
||||
@@ -55,18 +73,16 @@ Input download(const string &address)
|
||||
{
|
||||
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);
|
||||
CURL *curl = curl_easy_init();
|
||||
if (curl)
|
||||
|
||||
// res = curl_easy_perform(curl);
|
||||
|
||||
if (res != CURLE_OK)
|
||||
{
|
||||
CURLcode res;
|
||||
/* set options */
|
||||
/* Perform the entire transfer */
|
||||
res = curl_easy_perform(curl);
|
||||
/* Check for errors */
|
||||
if (res != CURLE_OK)
|
||||
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);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
@@ -75,12 +91,17 @@ Input download(const string &address)
|
||||
|
||||
return input_data(buffer, false);
|
||||
}
|
||||
int
|
||||
main(int argc, char* argv[]) {
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Input input;
|
||||
if (argc > 1) {
|
||||
if (argc > 1)
|
||||
{
|
||||
input = download(argv[1]);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
input = input_data(cin, true);
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user