#include <iostream>
#include <fstream>
using namespace std;
bool isLoggedIn(){
string username, password, name, pass;
cout << "Enter username: "; cin >> username;
cout << "Enter password: "; cin >> password;
ifstream readf(username + ".txt");
getline(readf, name); // line 1
getline(readf, pass); // line 2
if(name == username && pass == password){
return true;
} else{
return false;
}
}
int main()
{
int choice;
cout << "1. Register | 2. Login\nChoose: "; cin >> choice;
if(choice == 1){
string username, password;
cout << "Create username: "; cin >> username;
cout << "Create password: "; cin >> password;
ofstream file; // HERE, i am declaring the name of the file
file.open(username + ".txt"); // then am opening the file
file << username << endl << password; // writing
file.close(); // then closing it, but its not actually doing anything?
main();
} else if(choice == 2){
bool status = isLoggedIn();
if(!status){
cout << "Login failed" << endl;
system("pause");
return 0; // since main() is int., 0 = false
} else {
cout << "Login successful" << endl;
system("pause");
return 1; // 1 = true
}
}
}
I have no idea why the file is not being created, I dont think i need to specifically tell it where to create the file, since there are no errors, i am very new in c++ so i would appreciate it if you can thoroughly explain what the issue is, and maybe how can i clean up my code, thank you!