c++ - 匹配来自输入和文本文件 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;
}
解决方案
推荐阅读
- cordova - 使用 Ionic 4 和 Cordova 的 Google Plus 登录不起作用
- postgresql - grafana postgres 数据源测试返回“指标请求错误”
- python - 如何输入其中包含两个正斜杠的网址
- css - 使用 Bootstrap 容器,一列应拉伸到全宽并触摸屏幕右侧
- java - PreferenceFragmentCompat 中的 TimePicker(DialogFragment)
- python - 将图像从请求转换为 Pygame Surface
- python - 请求登录网站只得到 403 错误
- google-bigquery - 从 GCS 加载失败并显示“此表的表更新操作过多”
- python - Python列表理解执行顺序
- scala - 如何使用 IntelliJ IDEA IDE 创建使用 Maven 构建并包含 log4j 的 Scala 可执行 jar 文件