Код C++ для чтения удаленного текстового файла из URL-адреса и сохранения его как есть в массиве const char* []C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Код C++ для чтения удаленного текстового файла из URL-адреса и сохранения его как есть в массиве const char* []

Сообщение Anonymous »

Я пытаюсь создать программу cpp, которая будет читать удаленный файл по URL-адресу, например, http://10.10.10.10/file.txt
Файл содержит слова в этом формате «слово1», «слово2» ","word3"
Мне нужно сохранить содержимое файла в массиве "const char*wordslist[3]={"word1","word2","word3"}" как есть.

Код: Выделить всё

#include 
#include 
#include 
#include 
#include 

#pragma comment(lib, "wininet.lib")

// Function to parse the input string and populate the wordlist array
void parseAndPopulate(const std::string& input, const char** wordlist, int size) {
std::vector words;
size_t pos = 0;
while ((pos = input.find("\",\"", pos)) != std::string::npos) {
words.push_back(input.substr(1, pos - 1)); // Extract word between quotes
pos += 3; // Move past the ", delimiter
}
// Add the last word (no ", delimiter at the end)
words.push_back(input.substr(pos + 2, input.size() - pos - 3));
// Check if the size matches
if (words.size() != size) {
std::cerr  0) {
readBuffer.append(buffer, bytesRead);
}

// Close the URL file handle
InternetCloseHandle(hUrlFile);

// Parse the fetched data and populate the wordlist array
parseAndPopulate(readBuffer, wordlist, size);

// Print the populated wordlist array
for (int i = 0; i < size; ++i) {
std::cout 

Подробнее здесь: [url]https://stackoverflow.com/questions/78486110/c-code-to-read-remote-txt-file-from-url-and-store-it-as-is-to-const-char-a[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»