【发布时间】:2018-11-23 03:32:38
【问题描述】:
我现在正在做一个学校项目,我需要用 QT 构建一个学生管理系统。我有一个 txt 文件,其中列出了学生信息,如下所示:
Studentname accountpassword studentid
每次用户(学生)输入他们的学生姓名和密码时,我都必须检查姓名和密码是否在数据库中(现在是 txt 文件)。
这就是我现在正在努力解决的问题。我不知道我如何只能逐行搜索。例如,如果第一个学生用户名是jack,他的密码是123456;同时,第二个学生用户名为peter,密码为23567。
如何查看用户名jack和123456是否同时输入?
void MainWindow::on_loginpush_clicked()
{
QString username = ui -> lineedit_username -> text();
QString password = ui -> lineedit_password -> text();
if (username == "admin" && password =="admin")
{
Adminmanagment adminview;
adminview.exec();
}
else if( (username != "admin") && (password !="admin"))
{
ifstream studentinfo("student.txt");
if (!studentinfo.is_open())
{
}
else
{
string current_name;
string current_password;
string id;
int numofcourses;
int gpa;
char newline;
char space;
bool valid =false;
while((studentinfo>>current_name>>current_password>>id>>numofcourses>>gpa>>noskipws>>newline) &&newline == '\n')
{
if((current_name == username)&& (current_password== password))
{
}
}
}
}
我的 student.txt 如下所示
姓名密码id课程gpa数
jack 123456 900440123 4 0
testing 987654 900542015 4 2
testing2 8888 900145265 4 2
testing3 8888 900158256 4 0
【问题讨论】:
-
您需要查看使用 std::getline 以及字符串标记化。
-
您好,先生,谢谢您的回答,我马上去看看。