我m passing user login details to my 'login()' function. I
使用if语句返回成功或失败。但是我怎样才能将其中一个值归还给我的主要()'功能和显示给用户?
谢谢你的帮助。
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
string login(string username, string password)
{
string un, pw;
ifstream read("../../" + username + ".txt");
getline(read, un);
getline(read, pw);
if (un == username && pw == password)
{
//cout << "Succesfully logged in!" << endl;
string result = "success";
return result;
}
else
{
//cout << "False login!" << endl;
string result = "failure";
return result;
}
}
int main()
{
cout << "Please login: " << endl;
string username, password;
cout << "Enter username: "; cin >> username;
cout << "Enter password: "; cin >> password;
cout << login();
}