Skip to content
Snippets Groups Projects
Commit 7ab6a749 authored by Eraser's avatar Eraser
Browse files

Aufgabe 5 done

parent 0a121e66
No related branches found
No related tags found
No related merge requests found
...@@ -86,4 +86,31 @@ void saveCardsToFile(const std::list<Cards>& cardsList) { ...@@ -86,4 +86,31 @@ void saveCardsToFile(const std::list<Cards>& cardsList) {
file.close(); 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;
}
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
std::list<Cards> getListOfCards(const std::string& filename); std::list<Cards> getListOfCards(const std::string& filename);
void saveCardsToFile(const std::list<Cards>& CardsList); void saveCardsToFile(const std::list<Cards>& CardsList);
std::list<std::string> referenceNames(const std::string& referenceFile);
......
...@@ -25,6 +25,8 @@ int main() { ...@@ -25,6 +25,8 @@ int main() {
test = getListOfCards("/Users/erayduzenli/CLionProjects/magicCards/scrambled.txt"); test = getListOfCards("/Users/erayduzenli/CLionProjects/magicCards/scrambled.txt");
//TODO why does it save the file in the debug folder //TODO why does it save the file in the debug folder
saveCardsToFile(test); saveCardsToFile(test);
referenceNames("/Users/erayduzenli/CLionProjects/magicCards/reference.txt");
return 0; return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment