From 6869f9788ea0104ba87a2b67accfc173201cc238 Mon Sep 17 00:00:00 2001 From: Monoki Dorina <mondo1@cortex.itk.ppke.hu> Date: Sun, 12 May 2024 10:22:13 +0200 Subject: [PATCH] fajl beolvasas es iras mukodik --- fe1.txt | 2 +- gamemaster.cpp | 44 +++++++++++++++++++------------------------- gamemaster.hpp | 6 +++--- mo1.txt | 2 +- save.txt | 10 +--------- 5 files changed, 25 insertions(+), 39 deletions(-) diff --git a/fe1.txt b/fe1.txt index 1522c99..5a61e0c 100644 --- a/fe1.txt +++ b/fe1.txt @@ -1 +1 @@ -985601000006540021000030000807904100530007986190800000003070600020085300708306000 \ No newline at end of file +9 8 5 6 0 1 0 0 0 0 0 6 5 4 0 0 2 1 0 0 0 0 3 0 0 0 0 8 0 7 9 0 4 1 0 0 5 3 0 0 0 7 9 8 6 1 9 0 8 0 0 0 0 0 0 0 3 0 7 0 6 0 0 0 2 0 0 8 5 3 0 0 7 0 8 3 0 6 0 0 0 \ No newline at end of file diff --git a/gamemaster.cpp b/gamemaster.cpp index 9641708..27d233a 100644 --- a/gamemaster.cpp +++ b/gamemaster.cpp @@ -59,27 +59,26 @@ bool GameMaster::szabalyos_e(Index jelenlegi) } -std::vector<std::vector<int>> GameMaster::fajl_beolvasas(std::string fajlnev) +std::vector<int> GameMaster::fajl_beolvasas(std::string fajlnev) { - std::ifstream fajl; - fajl.open(fajlnev); + std::ifstream fajl(fajlnev); + std::vector<int> v; - std::vector<std::vector<int>> teljes; - for (int i=0; i<9; i++) + if (!fajl.good()) + { + cout << "NEM JO A FAJL" << endl; + } + + for (int i=0; i<81; i++) { int szam; - std::vector<int> sor; - for (int j=0; j<9; j++) - { - fajl >> szam; - cout << szam << endl; - sor.push_back(szam); - } - fajl >> ws; - teljes.push_back(sor); + fajl >> szam; + v.push_back(szam); + cout << szam << " "; } fajl.close(); - return teljes; + + return v; } void GameMaster::save() @@ -87,18 +86,13 @@ void GameMaster::save() fajl_kiiras(_fajl_save,_save); } -void GameMaster::fajl_kiiras(std::string fajlnev,std::vector<std::vector<int>> v) const +void GameMaster::fajl_kiiras(std::string fajlnev,std::vector<int> v) const { - std::ofstream fajl; - fajl.open(fajlnev); - - for (vector<int> sor : v) + std::ofstream fajl(fajlnev); + for (int ertek : v) { - for (int ertek : sor) - { - fajl << ertek; - } - fajl << endl; + fajl << ertek << " "; } + fajl << endl; fajl.close(); } diff --git a/gamemaster.hpp b/gamemaster.hpp index 0c54b72..802f7a9 100644 --- a/gamemaster.hpp +++ b/gamemaster.hpp @@ -10,8 +10,8 @@ class GameMaster { public: GameMaster(std::string mo, std::string fe); - std::vector<std::vector<int>> fajl_beolvasas(std::string fajlnev); - void fajl_kiiras(std::string fajlnev, std::vector<std::vector<int>> v) const; + std::vector<int> fajl_beolvasas(std::string fajlnev); + void fajl_kiiras(std::string fajlnev, std::vector<int> v) const; void save(); std::vector<Index> aura(Index); virtual int negyzet_szama(Index); @@ -20,7 +20,7 @@ class GameMaster protected: std::string _fajl_megoldas, _fajl_feladat, _fajl_save; - std::vector<std::vector<int>> _megoldas, _feladat, _save; + std::vector<int> _megoldas, _feladat, _save; }; #endif // GAMEMASTER_HPP diff --git a/mo1.txt b/mo1.txt index 890d777..e0e3317 100644 --- a/mo1.txt +++ b/mo1.txt @@ -1 +1 @@ -985621473376549821241738569867954132534217986192863754453172698629485317718396245 \ No newline at end of file +9 8 5 6 2 1 4 7 3 3 7 6 5 4 9 8 2 1 2 4 1 7 3 8 5 6 9 8 6 7 9 5 4 1 3 2 5 3 4 2 1 7 9 8 6 1 9 2 8 6 3 7 5 4 4 5 3 1 7 2 6 9 8 6 2 9 4 8 5 3 1 7 7 1 8 3 9 6 2 4 5 \ No newline at end of file diff --git a/save.txt b/save.txt index 8556494..76742c8 100644 --- a/save.txt +++ b/save.txt @@ -1,9 +1 @@ -214748364721474836472147483647214748364721474836472147483647214748364721474836472147483647 -214748364721474836472147483647214748364721474836472147483647214748364721474836472147483647 -214748364721474836472147483647214748364721474836472147483647214748364721474836472147483647 -214748364721474836472147483647214748364721474836472147483647214748364721474836472147483647 -214748364721474836472147483647214748364721474836472147483647214748364721474836472147483647 -214748364721474836472147483647214748364721474836472147483647214748364721474836472147483647 -214748364721474836472147483647214748364721474836472147483647214748364721474836472147483647 -214748364721474836472147483647214748364721474836472147483647214748364721474836472147483647 -214748364721474836472147483647214748364721474836472147483647214748364721474836472147483647 +9 8 5 6 0 1 0 0 0 0 0 6 5 4 0 0 2 1 0 0 0 0 3 0 0 0 0 8 0 7 9 0 4 1 0 0 5 3 0 0 0 7 9 8 6 1 9 0 8 0 0 0 0 0 0 0 3 0 7 0 6 0 0 0 2 0 0 8 5 3 0 0 7 0 8 3 0 6 0 0 0 -- GitLab