登录系统 - 返回主要成功或失败

时间:2016-04-29 19:24:40

标签: string function login return-value username

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();     

}

0 个答案:

没有答案