This is for a personal project. Inside of userlist.txt I have a username, a space, and then the password to go along with that username. A newline denotes a new username/password combination. The above code works for me but I would really appreciate some advice on whether I'm doing that an efficient way or if there is a better way.
I also understand that during the addition to userlist.txt I must make sure a username does not exceed 15 characters and a password does not exceed 15 characters.
I try to avoid messing around with the seekg method, it can behave weird/slow and when you use it you are assuming all the data is perfectly formatted in your file.
I personally would change the seekg calls to just use the ws stream modifier. This way, your program won't crash if the data has 2 spaces between the username and password by accident, or if there is a blank line between some of the data. It will all still work properly.
The other thing is, you should always check for .good() instead of !.eof()
Finally, by using .get() with a 15 char limit, you never report that there is a problem. It is just going to get the first 15 chars, then the next time it reads it will start in the same word and start reading, then stop at the space. So you'll end up with half words and mismatched username/password combos.