Файл содержит слова в этом формате «слово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]
Мобильная версия