Okay, so I have a player name vector within a class as well as a functioning register and login system that reads from files. (Ex: Allura.txt, or Bob.txt). Usernames and passwords are saved seperated by a ";", which I use as a delimiter with the getline function:
Now I'm stuck. I've created a command for whenever a player enters 'stats'. What is the best solution for C++ to know which player is typing stats, and to print those statistics of that player from the vector without prompting the player to define their name to search through the vector every time? I could use temporary variables but if more than one player enters stats, that variable will be overwritten to the next player.
I will explain more clearly if needed; I've been confused with this for days.
1. the class declaration if not the full definitions (you can post your code at pastie, etc if the file is too large) and copy a link here
2. couple of sample lines from filename, filepass
3. the int main() program
By design, in your program, each class object has the entire vector of all the players and so it is difficult to distinguish between them. Take a step back and consider what you're trying to do and you'll see that you don't even need a class to achieve your goals, the file design can handle all the functionalities of the class. Your goals are to:
(a) to set up a file to save players' names and passwords
(b) add a player (unique names only)
(c) search a player and, if found, return name and password
Once the file is set-up, and you still wish to, it is very simple to define a class/struct with name and password, overload insertion/extraction operators and do any kind of further processing