我在做C++。我想比较用户在整个texfile文件中输入的内容。
我的文本文件是这样的:比较用户输入和文本文件
库马尔印度9102223403434名1980年1月2日新加坡航空8118精英 -
我一共有15个数据项。 最重要的是,如果用户未能输入正确的数据,则只有3次尝试。
这是我的代码。请指教。
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
void Member();
using namespace std;
int main()
{
int option;
string member;
cout<<"\tWelcome!\n";
cout<<"\n1. Member"<<endl;
cout<<"2. Non member"<<endl;
cout<<"Please enter your option."<<endl;
cin>>option;
system("cls");
{
if (option==1)
{
Member();
}
else if (option==2)
{
cout<<"awesome";
}
else
cout<<"Invalid choice!";
}
system("pause");
return 0;
}
void Member()
{
ifstream inFile;
string userName,userNationality,airline,userType,type,userBirthday,birthday,userContact,Tmiles,userBenefit;
bool found=false;
for (int i=0; i<3; i++)
{
cout << "Enter birthday: ";
cin>>birthday;
inFile.open("list.txt");
if (!inFile)
cout << "Unable to open file"<<endl;
else
{
while (!inFile.eof())
{
inFile >> userName >> userNationality >> userContact >> userBirthday >> airline >> Tmiles >> userType >> userBenefit;
if (inFile.fail())
break;
else if (userBirthday == birthday)
{
system("cls");
cout<<"welcome"<< " " << userName <<"!" << endl;
found=true;
break;
}
}
}
}
inFile.close();
if (!found) //found==false
cout<<"You have exceed the limit. PLease try again"<<endl;
}
我的建议是问一个问题。除非你问具体问题,并描述什么不适合你,那么你不会得到任何帮助 – john
哦是的。对此感到遗憾。我的问题是我无法比较用户输入。即使我输入了在我的文本文件中找到的数据,它也只是提示输入不同的数据。 – user5207716