From f96cc33a72d75d67792376f9770b04127574d188 Mon Sep 17 00:00:00 2001 From: Loke Nesse Svelland <lokens@stud.ntnu.no> Date: Fri, 29 Apr 2022 04:49:40 +0200 Subject: [PATCH] tried to make read and write to files work --- src/kode/player.cpp | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/kode/player.cpp b/src/kode/player.cpp index 772ed36..a8a3c59 100644 --- a/src/kode/player.cpp +++ b/src/kode/player.cpp @@ -86,12 +86,17 @@ void Player::calculateScore() */ void Player::writeToFilePlayer(ofstream &out) { - out << setw(80) << firstName - << setw(80) << lastName - << setw(80) << rating - << setw(80) << playerID - << setw(80) << club - << "\n"; + out << firstName << '\n' + << lastName << '\n' + << rating << '\n' + << playerID << '\n' + << club << '\n' + << white << '\n'; + for(int i = 0; i < results.size(); i++) + out << results[i]; + out << '\n'; + for(int i = 0; i < playedAgainst.size(); i++) + out << playedAgainst[i]; } /** @@ -101,13 +106,22 @@ void Player::writeToFilePlayer(ofstream &out) */ void Player::readFromFilePlayer(ifstream &in) { + int inn; + getline(in, firstName); getline(in, lastName); - in >> rating; - in.ignore(); - in >> playerID; - in.ignore(); + in >> rating; in.ignore(); + in >> playerID; in.ignore(); getline(in, club); + in >> white; in.ignore(); + while(!'\n') { + in >> inn; + results.push_back(inn); + } + while(!in.eof()) { + in >> inn; + playedAgainst.push_back(inn); + } } int Player::currentRank(int id) @@ -147,4 +161,4 @@ bool Player::hasPlayedAgainst(int id) } } return false; -} \ No newline at end of file +} -- GitLab