gpt4 book ai didi

c++ - 编译器没有看到第一行?

转载 作者:行者123 更新时间:2023-11-28 00:38:06 24 4
gpt4 key购买 nike

我正在尝试从文本文件内容中搜索和匹配输入,文件内容是:

ManagerMohab123456789EmployeeSarah987654321.

It doesn't read the 1st line and searching about another user outputs the 2 if conditions!

Here is my code:

    cout << "Username : ";
cin >> usrname;
cout << "Password : ";
cin >> password;
fstream myfile;
myfile.open("Data.txt");

if (myfile.is_open())
{
while ( getline (myfile,line) )
{
myfile >> culmn1 >> culmn2 >> culmn3;
if(usrname==culmn1 && password==culmn2)
{
cout << culmn1 << culmn2 <<culmn3;
//cout << "Logedin Successfuly\n" ;
}
else cout << "Wrong Username or Password!\n";
}

myfile.close();
}
else cout << "Unable to open the file!\n";

提前感谢您的帮助:)

最佳答案

这个:

getline (myfile,line)

将从流 myfile 中消费一行。

关于c++ - 编译器没有看到第一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20150244/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com