Code

[Absolute C++] Ch4-16

BIGFROG 2019. 9. 19. 11:24
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

using namespace std;

void getHighScore(string& name, string& score) {
 int highScore = 0;
 string highScorePlayer;

 fstream inputStream;


 inputStream.open("scores.txt");
 while (! inputStream.eof()) {
  inputStream >> name;
  inputStream >> score;

  int score_int = atoi(score.c_str());

  cout << "현재 읽는 부분 : " << name << " " << score_int << endl;
  if (highScore < score_int) {
   highScorePlayer = name;
   highScore = score_int;
  }
 }
 inputStream.close();
 cout << endl;
 cout <<"=>Who is the best? "<< highScorePlayer << " " << highScore << endl;
}

int main() {
 string score;
 string name;
 
 getHighScore(name, score);

 return 0;
}