How to fix this login in C++? [closed]

  Kiến thức lập trình

I need some help. I am trying to make a log in and sign up page in C++. I’m currently following a tutorial on how to do it but it doesn’t seem to be working. Here’s my code:

#include <iostream>
#include <fstream>
#include <string>
std::string username, password, un, pw;
void signUp(){
    std::cout << "Enter your username: ";
    std::cin >> username;
    std::cout << "Enter your password: ";
    std::cin >> password;
    std::ofstream registerAccount;
    registerAccount.open(username + ".txt");
    registerAccount << "Username: " << username << std::endl << "Password: "<< password;
    registerAccount.close();
}

void logIn(){
    std::cout << "Enter your username: ";
    std::cin >> username;
    std::cout << "Enter your password: ";
    std::cin >> password;
    std::ifstream registerAccount;
    registerAccount.open(username + ".txt");
    std::getline(registerAccount, un);
    std::getline(registerAccount, pw);
    if(un == username and pw == password){
        std::cout << "You are now logged in!";
    }
}
int main(){
    logIn();
    return 0;
}

If anyone could help me, please and thank you (Also I already made a file for the account so I’m not sure why it isn’t working)

For the log in part to work

New contributor

user25087557 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

11

LEAVE A COMMENT