I'm trying to make a program that gets input from the user and enters it in the "accinfo".txt, basically a register/login program. but i'm getting problems. When i try to login it says it's the incorrect login info but it's correct. Please tell me what i'm doing wrong or if my logic is wrong, I'm still a beginner started learning 2 days ago.
You declare variables 'rname' and 'rpass' inside your login function, on line 40. By default, std::strings are empty.
Then, you enter information into 'lname' and 'lpass', but rname and rpass remain as empty strings.
In other words, you are not setting rname or rpass to what you think you're setting them to. Try using a debugger and viewing what the value of each string is. Or, print rname/rpass to the screen temporarily for troubleshooting.
Also, the ofstream that you open on line 46 is just overwriting whatever used to be in accinfo.txt, and nothing else.
If you're trying to compare your string against what's saved in your file, you need to open the file for reading.
When i try this code, it says that rname and rpass are not declared in this scope, even tho i opened the "accinfo.txt" file for reading. This is the only problem and i don't know how to fix it. this is the current code
Basically the rname/rpass used in login() are not those in reg(). login() knows nothing about reg() and its variables. Use one set of variables for the user entered data and one set for the data read from the file.