将帐户存储在文件中。 [英] Storing account in a file.

查看:75
本文介绍了将帐户存储在文件中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码。关键是如果用户没有帐户,则会创建帐户。这样可行。但当他要在那里的某个地方登录时,它会将用户名和密码设置为"true"。 

Here is my code. The point is that the user makes an account if he does not have one. That Works. But when he are gonna log in somewhere around there it sets the username and password to "true". 

int main() {

    takeAccount.open(" data.dat");

    takeAccount>> hasAccount;

    takeAccount.close();

    if(hasAccount!=" tre"){

        cout<< "请创建一个帐户:" << endl;

        cout<< "用户名:" ;;

        cin>>用户名;

        cout<< " Password:";

        cin>>密码;

        cout<<密码<< "&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; " <<用户名<< endl;

        saveUser.open(" data.dat");

        saveUser<<用户名;

        saveUser.close();

        savePass.open(" data.dat");

        savePass<<密码;

        savePass.close();

        hasAccount =" true"; $
        saveAccount.open(" data.dat");

        saveAccount<< hasAccount;

        saveAccount.close();

    }
    while(loginscreen == true){

int main() {
    takeAccount.open("data.dat");
    takeAccount >> hasAccount;
    takeAccount.close();
    if(hasAccount != "tre") {
        cout << "Please create an account:" << endl;
        cout << "Username: ";
        cin >> username;
        cout << "Password: ";
        cin >> password;
        cout << password << "      " << username << endl;
        saveUser.open("data.dat");
        saveUser << username;
        saveUser.close();
        savePass.open("data.dat");
        savePass << password;
        savePass.close();
        hasAccount = "true";
        saveAccount.open("data.dat");
        saveAccount << hasAccount;
        saveAccount.close();
    }
    while(loginscreen == true) {

  &NBSP; &NBSP;&NBSP; //我认为这附近有一个地方 - >

       //I think there is somewhere around here ->

        takeUser.open(" data.dat");

        takeUser>>用户名;

        takeUser.close();

        takePass.open(" data.dat");

        takePass>>密码;

        takePass.close();

        cout<< "请登录:" << endl;

        cout<< "用户名:" ;;

        cin>> inuser;

        cout<< " Password:";

        cin>> inpass;

       睡眠(3000);

        if(inuser == username&& inpass == password){

            cout<< "成功登录!" << endl;

            loginscreen = false;

            startscreen = true;

            system("cls");
$
        }
       否则{

            system(" cls");&
            cout<< "用户名或密码错误。再试一次。" << endl;

           睡眠(1500);

            system("cls");
$
        }
    }

        takeUser.open("data.dat");
        takeUser >> username;
        takeUser.close();
        takePass.open("data.dat");
        takePass >> password;
        takePass.close();
        cout << "Please log in:" << endl;
        cout << "Username: ";
        cin >> inuser;
        cout << "Password: ";
        cin >> inpass;
        Sleep(3000);
        if(inuser == username && inpass == password) {
            cout << "Successful Login!" << endl;
            loginscreen = false;
            startscreen = true;
            system("cls");
        }
        else {
            system("cls");
            cout << "Wrong username or password. Try again." << endl;
            Sleep(1500);
            system("cls");
        }
    }

推荐答案

这看起来像是一个类赋值。因此,帮助您的最佳方法是帮助您自己解决问题。

This looks like a class assignment. Therefore the best way to help you is to help you figure it out yourself.

您没有显示"hasAccount"的内容。是的,知道它是什么可能很重要。

You don't show what "hasAccount" is and knowing what it is is probably important.

尽我所知,你正在阅读"hasAccount"。但你写的是:

As best as I can tell, you are reading into "hasAccount" but you are writing out:


  • 用户名
  • 密码(oooops;用户名被覆盖并丢失)

因此,下次程序运行时,会将密码输入"hasAccount"。当您查看"data.dat"的内容时,您看到了什么?

So the next time the program runs it gets the password into "hasAccount". What do you see when you look at the contents of "data.dat"?

我不确定该程序应该如何工作。你能描述它应该如何用于可能用于向(非程序员)用户描述它的单词吗?用户应该看到和做什么以及结果应该是什么?作为一个优秀的
程序员,能够用这种技术描述程序真的很有帮助。

I am not sure how the program is supposed to work. Can you describe how it is supposed to work in the words that might be used to describe it to the (non-programmer) user? What is the user supposed to see and do and what should be the results? As a good programmer it will really help to be able to describe programs using that technique.


这篇关于将帐户存储在文件中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆