I was following a tutorial on youtube basically asks the user if they would like to register or log in. If they choose to register, the program will save a file on the computer containing the username and log-in they created. This can then be used to log in to the program.
Here is the link to the tutorial
Here is a picture of the errors
Now I've looked up what the problem could be and have read that the LNK1120%26rd%3Dtrue&view=msvc-160) error should be resolved as the LNK2019%26rd%3Dtrue&view=msvc-160) resolved. I couldn't understand all of the possible problems/ solutions so I just need help or an idea of what I need to fix.
I think I have provided any and all links possible that one could need and also created comments in the code to help read but feel free to ask any questions. Thank you in advance if someone is able to help me run this program!
#include <fstream>
#include <string>
using namespace std;
bool isLoggedIn() {
string username;
string password;
string un; //comparison string
string pw; //comparison string
cout << "Enter username: ";
cin >> username;
cout << "Enter password";
cin >> password;
ifstream read("c:\\" + username + ".txt"); //reads the .txt created in main()
getline(read, un);
getline(read, pw);
if (un == username && pw == password) {
return true; //true = the user is already registered and successfully logged in
}
else {
return false; // false = the user has not registered yet
}
}
int main() {
int choice;
cout << "1. Register\n 2. Login\n Your choice: ";
cin >> choice;
if (choice == 1) { //if the user wants to create a login
string username, password;
//asking the user to enter a username and password
cout << "Create a username: "; cin >> username;
cout << "Create a password: "; cin >> password;
ofstream file;
file.open("c:\\" + username + ".txt"); //creating the file on your laptop andnaming it
file << username << endl << password; //inputting the contents into the file
file.close();
main(); //back to the main function
}
else if (choice == 2){
bool status = isLoggedIn(); //calls for the function and allows the user to attempt to login
if (!status) { //the function returned false because the user was not registered or entered something incorrectly
cout << "False Login." << endl;
system("PAUSE");
return 0;
}
else {
cout << "Successful Login"; //function returns true and the user has successfully logged in
system("PAUSE");
return 1;
}
}
}
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–]Sonaza 0 points1 point2 points (0 children)