【发布时间】:2011-04-22 23:52:30
【问题描述】:
我需要从 .txt 文件中提取用户名和密码,但我很难思考究竟如何做到这一点。我会尝试分解它。
- 打开文件
- 读入用户名
- 将用户名与用户输入进行比较
- 将密码与与用户名关联的用户输入进行比较
- 如果用户名和密码匹配,则返回 true 或 false
是的,这是作业。我正在学习如何在等待 USPS 运送我的课本 txt 时使用 fstream。非常感谢您的帮助!
这是我目前所拥有的:
bool User::check(const string &uname, const string &pass)
{
//open the file
fstream line;
line.open("users.txt");
//Loop through usernames
//If a username matches, check if the password matches
}
users.txt 文件如下所示:
ali87 8422
ricq7 bjk1903
messi buneyinnessi
mike ini99ou
jenny Y00L11A09
end
【问题讨论】:
-
Mike,我想问一下你认为这个项目的“高水平”目标是什么?看起来它比仅仅理解 fstream 还要多一点……我说得对吗? (老师们真的很喜欢这样做,在每项作业中都加入“额外的学习”,他们认为自己是谁!)