#include <iostream>
#include <istream>
#include <fstream>
#include <iomanip>
#include <string>
usingnamespace std;
void FindName(string, string, string);
void PhoneNumber(string);
int main()
{
string firstName; // First Name
string lastName; // Last Name
string number; // Phone Number
string searchName; // First and Last Name Input
ifstream inFile;
inFile.open("phoneDirectory.dat"); // Opens input file
if ( !inFile )
{
cout << "Can't open input file." << endl;
}
cout << "Input the first and last name to lookup: ";
cin >> firstName >> lastName;
searchName = firstName + " " + lastName;
cout << searchName << "'s number is: " << number << endl; // Outputs phone number
cout << "Would you like to lookup another number?" // Asks user if they want to search for another number
<< "Enter y for yes or n for no; " << endl;
cin.get();
while (cin.get() == 'y') // If user wants to do another search
{
cout << "Input the first and last name to lookup: "; // Output Line
cin >> firstName >> lastName; // Input Line
searchName = firstName + " " + lastName; // Initialize variable
cout << searchName << "'s number is: " << number << endl;
cout << "Would you like to lookup another number?"
<< "Enter y for yes or n for no; " << endl;
cin.get();
}
inFile.close();
return 0;
}
void findName(string, string, string)
{
ifstream inFile;
string searchName;
inFile.open("phoneDirectory.dat");
while (inFile.good())
{
string lastName, firstName, number;
inFile >> firstName >> lastName >> number;
searchName = firstName + " " + lastName;
}
while (inFile.bad()) // If name is not in the directory
{
cout << "Name is not in directory. Please try again." << endl;
}
}
void findNumber (string)
{
ifstream inFile;
string number;
inFile.open("phoneDirectory.dat");
}