Was doing this project for school, but i cant get it to run, it's a telephone directory project here's the code
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
char getChoice()
{
char choice;
cout<<endl<<"Do you want to look for another? ";
cin>>choice;
return choice;
}
void getNames(string &strFName, string &strLName)
{
cout<<endl<<"Enter first name: ";
cin>>strFName;
cout<<"Enter last name: ";
cin>>strLName;
}
int findSubString(string line, string s)
{
return line.find(" ");
}
int main()
{
string line;
string fName,lName,tNumber, strFName, strLName;
char choice;
int flag=0;
int nextLoc=0;
cout<<"A Telephone Directory "<<endl;
do{
flag=0;
ifstream myfile ("input.txt");
if (myfile.is_open())
{
getNames(strFName,strLName);
while (! myfile.eof() )
{
getline (myfile,line);
nextLoc=findSubString(line," ");
fName=line.substr(0,nextLoc);
line = line.substr(nextLoc+1,line.length());
nextLoc=findSubString(line," ");
lName=line.substr(0,nextLoc);
line = line.substr(nextLoc+1,line.length());
tNumber = line;
if(fName==strFName && lName==strLName)
{
cout<<"Found!!"<<endl;
cout<<endl<<"First Name: "<<fName<<"\n"<<"Last Name: "<<lName<<"\n"<<"Telephone Number"<<tNumber<<endl ;
flag=1;
break;
}
}
}
else
{
cout << "Unable to open file"<<endl;
exit(0);
}
if(flag==0)
{
cout<<"Not Found...Sorry."<<endl;
}
choice = getChoice();
}while(choice=='y');
cout<<"Good Bye..."<<endl;
cin.get(),cin.get();
return 0;
}
here is the input file
Mark John 8876543455
John Mark 8888888885
Bob Jackob 8899999999
Billy Bob 3456789087
Jackob Billy 8876543333
Thanx