Skip to content
Snippets Groups Projects
Commit 0a121e66 authored by Eraser's avatar Eraser
Browse files

Aufgabe 4 done

parent 6e97f8d0
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <sstream> #include <sstream>
#include <vector> #include <vector>
//std::list<Cards> getListOfCards(const std::string& filename) // Aufgabe 3
std::list<Cards> getListOfCards(const std::string& filename) { std::list<Cards> getListOfCards(const std::string& filename) {
std::ifstream file(filename); std::ifstream file(filename);
if(!file) { if(!file) {
...@@ -64,4 +64,26 @@ std::list<Cards> getListOfCards(const std::string& filename) { ...@@ -64,4 +64,26 @@ std::list<Cards> getListOfCards(const std::string& filename) {
//return the cards as a list //return the cards as a list
return CardsList; return CardsList;
} }
\ No newline at end of file
// Aufgabe 4
void saveCardsToFile(const std::list<Cards>& cardsList) {
//Create new file
std::ofstream file("scrambledNew.txt");
//Check if file can be opened
if(!file) {
throw std::runtime_error("Error: Unable to open file.");
}
//Print every card object in CardsList into separate Line, add the vertical bar again
for (const auto& card : cardsList) {
file << card.name << "|" << card.mana << "|" << card.cmc << "|" << card.type << "|" << card.count << std::endl;
}
//Close file
file.close();
}
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
std::list<Cards> getListOfCards(const std::string& filename); std::list<Cards> getListOfCards(const std::string& filename);
void saveCardsToFile(const std::list<Cards>& CardsList);
...@@ -18,9 +18,13 @@ int main() { ...@@ -18,9 +18,13 @@ int main() {
s.name = "peter"; s.name = "peter";
s.type = "uwu"; s.type = "uwu";
std::cout << s.name << s.count << s.type << s.cmc << std::endl; std::cout << s.name << s.count << s.type << s.cmc << std::endl;
//To-Do, only absolute path works
*/ */
getListOfCards("/Users/erayduzenli/CLionProjects/magicCards/scrambled.txt"); std::list<Cards> test;
//TODO relative path doesnt work
test = getListOfCards("/Users/erayduzenli/CLionProjects/magicCards/scrambled.txt");
//TODO why does it save the file in the debug folder
saveCardsToFile(test);
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