This is what I was working with earlier:
That works for sending what I want to the file.Code:#include <iostream> #include <fstream> #include <string> using namespace std; int main () { string line; char name[16]; char pword[10]; ifstream readFile ("example.txt"); ofstream writeFile ("example.txt"); if (writeFile.is_open()) { cout << "Enter your username: "; cin >> name; cout << endl << "Enter your password: "; cin >> pword; cout << endl; writeFile << name << "\n"; writeFile << pword; writeFile.close(); } else cout << "Unable to open file"; if (readFile.is_open()) // if you can open the file { getline (readFile,line); // get 1 line from file and asave it to line cout << line << endl; // output the line readFile.close(); // close } else cout << "Unable to open file"; return 0; }
But I couldn't figure out how I would be able to access it an authorize a login making sure the username and password were for the right account.
What I was thinking was like what you said creating a file with the characters name and have the password inside the file and be like:
but when I was experimenting with that I couldn't find out how to make it so that the file created was set to the input of the character.Code:getline(readFile, line) if(pword == line) { //login was successful do whatever afterwards }
for example:
But that approach wasn't working for me, so now I'm lost again...Code:we.ll say the variable is userName and passWord user inputs PlayerA for userName, user inputs Orange for passWord ofstream writeFile(userName + ".txt") writeFile.open() writeFile << passWord writeFile.close()




Reply With Quote