主题:为什么电话号码查寻程序只能查寻一次<求高手>
我是大一学生,作业为编一个电话号码查寻程序,但我的程序只能查寻一次,第二次循环时就不输出了
希望前辈们指点一下,谢谢!(回加30分)
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
ifstream inFile;
string ans,F,L,firstname,lastname,firstName,lastName,number;
inFile.open("phonenumber.txt");
do
{
cout<<"Enter the firstname and lastname you want to look up:"<<endl;
cin>>firstname>>lastname;
do
{
inFile>>firstName>>lastName>>number;
if((firstname==firstName)&&(lastname==lastName))
{
cout<<firstName<<" "<<lastName<<" "<<number<<endl;
F=firstName;
L=lastName;
}
}while(inFile);
if(F!=firstname||L!=lastname)
{
cout<<"The name is not in the telephne directory"<<endl;
}
cout<<"Do you find it again?(Y/N)"<<endl;
cin>>ans;
}while(ans=="Y"||ans=="y");
inFile.close();
return 0;
}
以下为电话薄文件内容:
zhang shan 13435689
zhang hao 1564
li si 1245
li lan 15646
wang hao 156456
希望前辈们指点一下,谢谢!(回加30分)
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
ifstream inFile;
string ans,F,L,firstname,lastname,firstName,lastName,number;
inFile.open("phonenumber.txt");
do
{
cout<<"Enter the firstname and lastname you want to look up:"<<endl;
cin>>firstname>>lastname;
do
{
inFile>>firstName>>lastName>>number;
if((firstname==firstName)&&(lastname==lastName))
{
cout<<firstName<<" "<<lastName<<" "<<number<<endl;
F=firstName;
L=lastName;
}
}while(inFile);
if(F!=firstname||L!=lastname)
{
cout<<"The name is not in the telephne directory"<<endl;
}
cout<<"Do you find it again?(Y/N)"<<endl;
cin>>ans;
}while(ans=="Y"||ans=="y");
inFile.close();
return 0;
}
以下为电话薄文件内容:
zhang shan 13435689
zhang hao 1564
li si 1245
li lan 15646
wang hao 156456