I am making a user database. When I try to open the "dataBase.txt" which holds all of the users and passwords, the console pops up (which should happen since it is a console application) but it says that the program has already complete. When I close it, my computer tell me that the program had crashed. The function is saved in a class.
After some debugging the code seems to crash at ifstream fin("dataBase.txt");
No error is returned from the compiler.
The code for the function called is:
void User_Psw::UserCheck()
{
// read from the database
ifstream fin("dataBase.txt");
while (!fin.eof())
{
fin >> Usernames[sizeOfDatabase] >> Password[sizeOfDatabase];
sizeOfDatabase++; //The Number of lines in .txt
}
// rest of the program
cout << "Username: ";
cin >> username;
getNameIndex();
cout << "Password: ";
cin >> password;
if(!PasswordMatches())
{
cout << "Access denied";
}
}
I can add more code snippets if asked.
fin. If all else fails, read the documentation!UsernamesandPasswordsdeclared? Alsowhile (!fin.eof())is probably not doing what you think it's doing.Usernames[sizeOfDatabase]make me think somewhere out there is a vector/deque/array/fixed-array that is about to have the memory one element past its allotted size get stomped?Usernamesasstd::vector<std::string> Usernames;andPasswordasstd::vector<std::string> Password;And I think thatwhile (!fin.eof())is checking the number of lines in the file and then saving it to the variablesizeOfDatabasewhich I can then use as an index.