Advertisement
Guest User

Untitled

a guest
May 28th, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include<vector>
  2. #include<string>
  3. #include<fstream>
  4. #include<sstream>
  5. //pobieranie z pliku others/ranks.txt wynikow
  6. std::vector<std::string> getTopPlayers()
  7. {
  8.     std::string BestScores;
  9.     std::vector<std::string> scores;
  10.     std::ifstream Ranks("other/ranks.txt");
  11.     while(getline(Ranks,BestScores))
  12.     {
  13.         scores.push_back(BestScores);
  14.     }
  15.     return scores;
  16. }
  17. std::vector<std::string> explode(std::string variable)
  18. {
  19.     int i;
  20.     std::vector<std::string> r;
  21.     for(i=0; i<variable.size(); ++i)
  22.     {
  23.         if(variable[i]=='#') break;
  24.     }  
  25.     r.push_back(variable.substr(0,i));
  26.     r.push_back(variable.substr(i+1,variable.size()-1));
  27. }
  28. //zapis do pliku
  29. void SaveScore(std::string nick, int pkt)
  30. {
  31.     int i=0,number=0;
  32.     std::vector<std::string> scores;
  33.     std::vector<std::string> player; //nick # punkty
  34.     scores=getTopPlayers();
  35.     std::ofstream Ranks("other/ranks.txt");
  36.     while(i<scores.size())
  37.     {
  38.         player=explode(scores[i]);
  39.         //konwersja string->int
  40.         std::stringstream s;
  41.         s << player[1];
  42.         s >> number;
  43.         if(pkt>number)
  44.         {
  45.             Ranks << scores[i] << "\n";
  46.         }
  47.         else
  48.         {
  49.             Ranks << nick << "#" << pkt << "\n";
  50.         }
  51.         ++i;
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement