Guest User

Untitled

a guest
Jan 13th, 2017
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "Class.h"
  3.  
  4. using namespace std;
  5.  
  6.  
  7. string Player::convert_for_save()
  8. {
  9.     string name_s = name;
  10.     for (int i = 0; i <= name_s.size(); i++)
  11.         if (name_s[i] == ' ')
  12.             name_s.replace(i, 1, "_");
  13.     string for_save;
  14.     for_save.append(name_s);
  15.     for_save.append(" ");
  16.     for_save += to_string(score);
  17.  
  18.  
  19.  
  20.  
  21.     return for_save;
  22. }
  23.  
  24. Player::Player(string name)
  25. {
  26.     this->name = name;
  27.     score = 0;
  28. }
  29. Player::Player(string name, int score)
  30. {
  31.     this->name = name;
  32.     this->score = score;
  33. }
  34.  
  35. string Player::get_name()
  36. {
  37.     return name;
  38. }
  39.  
  40. int Player::get_score()
  41. {
  42.     return score;
  43. }
  44.  
  45. void Player::save_player_to_file()
  46. {
  47.     fstream save("data\\players.dab", ios::out | ios::app);
  48.     save << convert_for_save();
  49.     save << endl;
  50.     save.close();
  51.  
  52.  
  53.  
  54.  
  55. }
Add Comment
Please, Sign In to add comment