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;
}

'Code' 카테고리의 다른 글

[백준 1094] 막대기  (0) 2020.01.09
[C Programming] 에라토스테네스의 체  (0) 2020.01.09
[Absolute C++] Ch4-13  (0) 2019.09.19
[Absolute C++] Ch2-10  (0) 2019.09.19
[Absolute C++] Ch1-8  (0) 2019.09.19