Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<vector>
- #include<string>
- #include<fstream>
- #include<sstream>
- //pobieranie z pliku others/ranks.txt wynikow
- std::vector<std::string> getTopPlayers()
- {
- std::string BestScores;
- std::vector<std::string> scores;
- std::ifstream Ranks("other/ranks.txt");
- while(getline(Ranks,BestScores))
- {
- scores.push_back(BestScores);
- }
- return scores;
- }
- std::vector<std::string> explode(std::string variable)
- {
- int i;
- std::vector<std::string> r;
- for(i=0; i<variable.size(); ++i)
- {
- if(variable[i]=='#') break;
- }
- r.push_back(variable.substr(0,i));
- r.push_back(variable.substr(i+1,variable.size()-1));
- }
- //zapis do pliku
- void SaveScore(std::string nick, int pkt)
- {
- int i=0,number=0;
- std::vector<std::string> scores;
- std::vector<std::string> player; //nick # punkty
- scores=getTopPlayers();
- std::ofstream Ranks("other/ranks.txt");
- while(i<scores.size())
- {
- player=explode(scores[i]);
- //konwersja string->int
- std::stringstream s;
- s << player[1];
- s >> number;
- if(pkt>number)
- {
- Ranks << scores[i] << "\n";
- }
- else
- {
- Ranks << nick << "#" << pkt << "\n";
- }
- ++i;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement