c++ - C++用户登录程序只读取文件的第一行
问题描述
void abc::loginUser()
{
abc x;
fstream file;
char usr[25];
string pwd = "",line;
int ch;
file.open("user.txt"),ios::in;
cout << "User Login" << endl;
cout << "Username: ";
gets(usr);
cout << "Password: ";
file.seekg(0);
while(ch = getch())
{
if(ch == 13)
{
while(file)
{
file >> user.username >> user.password;
if(strcmp(usr,user.username)==0)
{
if(pwd != user.password)
{
file.close();
cout << "\nLogin Failed";
getch();
system("cls");
x.login();
}
else if(pwd == user.password)
{
file.close();
cout << "\nLogin Successful";
getch();
system("cls");
x.menuUser();
}
}
else if(strcmp(usr,user.username)!=0)
{
file.close();
cout << "\nUser Not Registered";
getch();
system("cls");
x.login();
}
else
{
file.close();
cout << "\nLogin Failed";
getch();
system("cls");
x.login();
}
}
}
else if(ch == 8)
{
if(pwd.length() > 0)
{
cout<<"\b \b";
pwd.erase(pwd.length()-1);
}
}
else
{
cout << "*";
pwd += ch;
}
}
}
有谁知道为什么程序只读取 user.txt 文件的第一行?我似乎找不到解决此问题的方法,尝试了 file.read 方法,但它也不起作用。
我应该改变什么来改进我的代码吗?
大家能帮帮我吗,这里是初学者。
(对不起我的英语不好,不是我的主要语言)
解决方案
推荐阅读
- r - 两个矩阵中所有元素的配对 T 检验
- javascript - Flowtype无法获取.clientHeight,因为Node中缺少属性clientHeight [prop-missing]
- django - Django 中的自定义字段未显示在管理面板中
- android - 如何更改工具栏中的android项目图标菜单的大小?
- ios - Swift 本地通知检查器仅主线程
- python - 从数据为字典格式的 pandas 数据列中提取值
- python - python selenium 找不到正确的对象。如何确定合适的框架?
- java - 两部手机之间的接近检测 (Android)
- javascript - MapBox 在 react native 中更新状态时不会更改 renderAnnoations ( setState(..) , forceUpdate() 对它没有影响)
- node.js - node.js socket.io : io.of('....')..... 似乎在页面加载和刷新时运行了两次代码