From 7ab6a749264491e117529c08c040d54a78e877c5 Mon Sep 17 00:00:00 2001 From: Eraser <erayduezenli@googlemail.com> Date: Thu, 13 Apr 2023 16:53:25 +0200 Subject: [PATCH] Aufgabe 5 done --- functions.cpp | 27 +++++++++++++++++++++++++++ functions.h | 1 + main.cpp | 2 ++ 3 files changed, 30 insertions(+) diff --git a/functions.cpp b/functions.cpp index 978d72f..c5e5ede 100644 --- a/functions.cpp +++ b/functions.cpp @@ -86,4 +86,31 @@ void saveCardsToFile(const std::list<Cards>& cardsList) { file.close(); } +//Aufgabe 5 +std::list<std::string> referenceNames(const std::string& referenceFile) { + std::ifstream file(referenceFile); + //check if file can be opened + if (!file) { + throw std::runtime_error("Error: Unable to open file " + referenceFile); + } + //output + std::list<std::string> namesList; + //temp for names + std::string name; + //read every line + while (std::getline(file, name)) { + namesList.push_back(name); + } + + //close file + file.close(); + + //for testing reasons + std::cout <<namesList.front() << std::endl; + std::cout <<namesList.back() << std::endl; + + + return namesList; +} + diff --git a/functions.h b/functions.h index abdd521..0cdcbfb 100644 --- a/functions.h +++ b/functions.h @@ -10,6 +10,7 @@ std::list<Cards> getListOfCards(const std::string& filename); void saveCardsToFile(const std::list<Cards>& CardsList); +std::list<std::string> referenceNames(const std::string& referenceFile); diff --git a/main.cpp b/main.cpp index 509aacd..1bd7891 100644 --- a/main.cpp +++ b/main.cpp @@ -25,6 +25,8 @@ int main() { test = getListOfCards("/Users/erayduzenli/CLionProjects/magicCards/scrambled.txt"); //TODO why does it save the file in the debug folder saveCardsToFile(test); + referenceNames("/Users/erayduzenli/CLionProjects/magicCards/reference.txt"); + return 0; } -- GitLab