[Absolute C++]Ch4-16
-----scores.txt-----
Ronaldo
10400
Didier
9800
Pele
12300
Kaka
8400
Cristiano
8000
--------------------
Ronaldo
10400
Didier
9800
Pele
12300
Kaka
8400
Cristiano
8000
--------------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #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; } |
댓글
댓글 쓰기