我正在创建一个存储默认密码的程序,当输入正确时,您可以更改它。问题是当我输入新密码时,当我关闭并打开程序时它不会保存。
#include<iostream>
#include<sstream>
using namespace std;
string inputC;
string yes = "yes";
string no = "no";
string password;
string input;
void correct()
{
cout << "Would you like to change the password?" << endl;
cin >> inputC;
if (inputC == yes)
{
cout << "Enter new password:" << endl;
cin >> password;
}
else
{
cout << "You now have access." << endl;
}
}
void enter()
{
cout << "Enter password: " << endl;
cin >> input;
if (input == password)
{
cout << "Correct" << endl;
correct();
}
else
{
cout << "Incorrect" << endl;
enter();
}
}
int main()
{
if (password.empty())
{
password = "password";
}
enter();
}
答案 0 :(得分:0)
据我所知,您使用代码创建的变量将转到RAM Memory,因此一旦程序完成,它们就会被销毁。为了保留新密码,您应该考虑将其写入外部文本文件或数据库。