For some reason this piece of code won't write the info to the txt file. I've been looking for a while and can't seem to find anything. Does anybody have any ideas? Thanks in advance.
elseif (!hasAnAccount) //If they need to register
{
//promptRegistration(); //Prompt Registration
string newUsername;
string newPassword;
userFile.open("usernameList.txt", ios::out || ios::trunc || ios::in || ios::app);
passFile.open("passList.txt", ios::out || ios::trunc || ios::in || ios::app);
if (!userFile.is_open() || !passFile.is_open()) {
cerr << "Error opening password files...\n";
}
cout << "What would you like your username to be?\t";
cin >> newUsername;
cout << "\nWhat would you like your password to be?\t";
cin >> newPassword;
userFile << newUsername << "\n"; //Appends the new username to the list
passFile << newPassword << "\n"; //Appends the new password to the list
for (int i = 0; i < numberOfAccounts; ++i) {
usernames.resize(usernames.size() + 1);
passwords.resize(passwords.size() + 1);
getline(userFile, usernames[i]);
getline(passFile, passwords[i]);
cout << "Loading...\n";
}
userFile.close();
passFile.close();
++numberOfAccounts;
cout << "Thank you for registering, you may now login.\n";
try putting the full folder path to the file in the open statement, or make sure the executable, and where the executable is called from if run from your IDE, are able to get to that file. Operating systems are pretty picky about this.
Thanks for the quick response. Essentially it is just supposed to append the new username and password to the txt file. I'm using visual c++ and I was able to access the file and use the information using ifstream just fine, so I didn't think that the path was an issue.