gpt-3.5-turbo-0125· OpenAI
WildChat-4.8M (AI2)
Исправь функцию readFromFile: void readFromFile(const std::string& filename) {…
- User
Исправь функцию readFromFile: void readFromFile(const std::string& filename) { std::ifstream file(filename); int n = 0;
codeif (file.is_open()) { int identificator; int v; int id; std::string line; file >> v; for (int i = 0; i < v; i++) { nodes.addSorted(i); } getline(file, line); // Считываем пустую строку после первого числа while (getline(file, line)) { istringstream iss(line); int id; iss >> id; // Считываем id while (iss >> line) { // Перебираем строку по 2 символа if (line.find(';') != string::npos) { // Если нашли символ ';', прерываем цикл break; } int dst = line[0]; int wght = line[1]; // Выводим dst и wght cout << "id: " << id << ", dst: " << dst << ", wght: " << wght << endl; ListNode* l = nodes.find(id); Edge e; e.dst = dst; e.wght = wght; l->adjList->addSorted(dst); l->edgesfrom.push_back(e); } } file.close(); } else { std::cerr << "Enable open file" << filename << std::endl; } } - Assistant
void readFromFile(const std::string& filename, LinkedList& nodes) { std::ifstream file(filename); int n = 0;
code