首页 > 解决方案 > 匹配来自输入和文本文件 C++ 的值

问题描述

我有一个由成员数据组成的文本文件。我正在开发一个程序,我们可以在其中使用帐号来匹配程序中的帐号以获取正确的会员数据。但我不知道为什么,程序不工作,我无法匹配值。谁能帮我确定错误是什么。

Membership.txt的内容

Mathavan|021127100897|MathavanKrishnan27@gmail.com|0167750575|1410065449|Mathavan1234|3|2022
Mathavan|021127100897|MathavanKrishnan27@gmail.com|0167750575|1410065448|Mathavan1234|3|2024
Mathavan|021127100897|MathavanKrishnan27@gmail.com|0167750575|1410065447|Mathavan1234|3|2022
string member_login(){
    title();
    fstream member;
    member.open("Membership.txt",ios::in);
    string pass_input, line, acc_num1, password1;
    int login_attempt = 0, count = 0 , account = 0;
    char dummy, resp, accno_input[25], name[25], icno[25],email [40], phone_number[25],acc_num[25],password[25],month[25], year[25];

    account_num:
    cout << "                                          Enter your account number : ";
    cin >> accno_input;

    ifstream file("Membership.txt");
    while (!file.eof()){
        getline(file, line);
        count++;
     }

    cout << accno_input;
    int i = 0;
    while(i <= count)
    {
        member.getline(name,25,'|');
        member.getline(icno,25,'|');
        member.getline(email,40,'|');
        member.getline(phone_number,25, '|');
        member.getline(acc_num,25, '|');
        member.getline(password,25,'|' );
        member.getline(month,25,'|' );
        member.getline(year, 25);

        cout << name << " ";
        cout << icno << " ";
        cout << acc_num << " ";
        cout << accno_input;

        if (acc_num == accno_input){
            account = 1;
            break;
        }

        i ++;
    }

    cout << account;

    member.close();

    if ( account != 1 ){
        cout << endl;
        cout << "                                  Your account not found !!!"<< endl;
        cout << "                                  Please try again !!" << endl << endl;
        cout << "                                  PLEASE ENTER ANY KEY TO CONTINUE >>> ";
        cin >> dummy;
        goto account_num;
    }

    password1 = password;
    cout << endl;
    cout << "                                          Enter your account password : ";
    cin >> pass_input;

    for (login_attempt = 1 ; login_attempt <= 2 ; login_attempt ++){
        if (pass_input == password1){
            cout << "Login Successful !!!";
            break;
        }

        cout << endl;
        cout << "Login Failed. Attempt " << login_attempt  << " of 3" << endl;
        cout << "Please re-enter Password: " ;
        cin >> pass_input;

        if (pass_input == password1){
            cout << "Login Successful !!!";
                break;
        }
    }

    if ( login_attempt == 3){
        cout << endl;
        cout << "Login Failed. Attempt 3 of 3";
    }

    return accno_input;
}

标签: c++

解决方案


推荐阅读