C++ 使用存储在c+中文本文件中的数据检查用户名和密码输入+;

C++ 使用存储在c+中文本文件中的数据检查用户名和密码输入+;,c++,C++,这是我的代码: ` void Customer::validate_cust_username_and_password() { string uname, pword; cout << "enter name: " << endl; cin >> uname; cout << "enter password: " << endl; cin >

这是我的代码:

`
void Customer::validate_cust_username_and_password()
    {
        string uname, pword;
        cout << "enter name: " << endl;
        cin >> uname;
        cout << "enter password: " << endl;
        cin >> pword;
        ifstream myfile("cust_username_and_password.txt");
        if (myfile.is_open())
        {
            while (!myfile.eof())
            {

                if (uname == cust_username && pword == cust_password)
                {
                    cout << "Login successfully." << endl;
                    cust_mainmenu();
                    break;
                }
                else
                {
                    cout << "Wrong username or password!" << endl;
                    break;
                }
            }

            myfile.close();
        }

    }
`  
`
无效客户::验证客户用户名和密码()
{
字符串uname,pword;
不能取消;
库特普沃德;
ifstream myfile(“cust_username_and_password.txt”);
如果(myfile.is_open())
{
而(!myfile.eof())
{
if(uname==cust\u用户名和pword==cust\u密码)
{

cout在您的
验证客户用户名和密码功能中,您从未读入用户名和密码。添加以下内容:

 myfile >> cust_username >> cust_password;

cust\u username
cust\u password
从未在该代码中的任何位置设置,因此它们将永远不会匹配用户的输入(除非用户输入空字符串).

客户用户名在哪里神奇地出现了。保罗·丹尼尔斯参与其中了吗。保罗,我收回这一点,你没有大卫·布莱恩那么坏,但也不是很多;
    string uname, pword;
    cout << "enter name: " << endl;
    cin >> uname;
    cout << "enter password: " << endl;
    cin >> pword;
    ifstream myfile("password.txt");
    if (myfile.is_open())
    {
        while (!myfile.eof())
        {

            if (uname == "test" && pword == "0000")
            {
                cout << "Login successfully." << endl;
                cust_mainmenu();
                break;
            }
            else
            {
                cout << "Wrong username or password!" << endl;
                break;
            }
        }

        myfile.close();
    }

}
不能取消; 库特普沃德; ifstream myfile(“password.txt”); 如果(myfile.is_open()) { 而(!myfile.eof()) { 如果(uname==“test”&&pword==“0000”) {
哦,对不起,“客户用户名”在我的“类客户”中,我没有在这里发布完整的代码。哦,对不起,“客户用户名”和“客户密码”在我的“类客户”中,我没有在这里发布完整的代码。如果我帮了忙,你也可以接受答案来帮助我:)你的意思是投票给@awesomeyi吗?我想,但上面说“投票需要15个声誉”:(通常最好解释一个解决方案,而不是仅仅发布几行匿名代码。你可以阅读,也可以
    string uname, pword;
    cout << "enter name: " << endl;
    cin >> uname;
    cout << "enter password: " << endl;
    cin >> pword;
    ifstream myfile("password.txt");
    if (myfile.is_open())
    {
        while (!myfile.eof())
        {

            if (uname == "test" && pword == "0000")
            {
                cout << "Login successfully." << endl;
                cust_mainmenu();
                break;
            }
            else
            {
                cout << "Wrong username or password!" << endl;
                break;
            }
        }

        myfile.close();
    }

}