如果我有一个用户记录在一行内如何找到登录的数据
C++ if i have a user records within a line how can find the data to login
下面的代码不从文件中获取数据。它总是显示You have entered wrong data!!!
,我需要从一行中选择用户名和密码的代码。
我的记录是这样的:username password name id Contactnumber
if(choose ==2)//teacher
{
string line=" ";
ifstream read("teacher.txt");
cout <<" Enter Username: "; cin >> username;
cout <<" Enter Password: "; cin >> password;
bool found = false;
while (getline(read,line))
{
stringstream ss(line);
ss>>un>>pw;
if (un == username && pw == password)
{
cout<<"You have logged in as Teacher!"<<endl;
found = true;
break;
//system("pause");
}
}
if(!found)
{
cout<<"nYou have entered wrong data!!!"<<endl;
}
read.close();
}
cin >> username;
cin >> password;
对象cin
表示标准输入(默认为键盘)。文件"teacher.txt"在代码中由对象read
表示。要从这个文件中读取,你应该这样写:
read >> username;
read >> password;
顺便说一下,read
是函数的好名字,但不是对象的好名字。
相关文章:
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 用c++从输入文件中读取另一行
- 读取文件的最后一行并输入到链接列表时出错
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 如何找出GDB的SIGTRAP核心转储的根本原因
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 从C++dll访问C#中的一行主要参数
- 函数何时会在c++中包含stack_Unwind_Resume调用
- 在C++中,我如何接受不同于同一行的用户输入
- 找不到QtResource文件中的文件
- Python中的for循环与C++有何不同
- VC++本机单元测试,找不到调试符号
- 如何从一行中读取特定数量的字符?(C++)
- RegGetValue在当前用户下找不到名称
- C++找出覆盖同一行的数组
- 找出(x,y)坐标的列表是矩阵中的一行还是列
- 找出一行有多少个最大列值