<分区>
我正在做一个项目,真的需要一些帮助。我已将我的变量存储到一个文件中,如下所示,但用制表符将它们分开。现在我想把它们作为单独的变量读出来,所以问题是,我如何在没有标签的情况下阅读它们?我必须解析字符串吗?
void fileManagement::appendCustomeRFile(const Customer &obj)
{
if(tryFile(CFile))
{
ifstream cfile(CFile);
cfile<<obj.ReturnCustomerId()<<"\t"<<obj.ReturnFName()<<"\t"<<obj.ReturnLName()<<"\t"<<obj.ReturnContactNumber()<<"\t"<<obj.RetrunBalance()<<"\n\r";
cfile.close;
}
}
这就是我目前从文件中读取的方式。
void viewCustomerInfo(string contact_N)//
{
tryFile(CFile);
bool found=false;
string retreivedId,retreivedFname, retreivedLname, retreivedNumber;
double retreivedBalance;
ofstream cfile(CFile);
if(cfile.is_open())
{
while(!cfile.eof())
{
cfile>>retreivedId>>retreivedFname>>retreivedLname>>retreivedNumber>>retreivedBalance;
if (retreivedNumber==contact_N)
{
found=true;
cout<<"_______________________________________CUSTOMER INFO_______________________________________\n"<<"Customer ID: "<<retreivedId<<"\nFirst Name: "<<retreivedFname<<"\nLast Name: "<<retreivedLname<<"\n";
cout<<"Contact Number: "<<retreivedNumber<<"\nCustomer Balance"<<retreivedBalance<<endl;
cout<<"___________________________________________________________________________________________"<<endl;
break;
}
}
}
}
非常感谢任何帮助。谢谢。