program read from cin what the user wants to do ("add" a name to list) or ("lookup" a name). in add just add whatever was read in to the file. in lookup print out a line of text with the string that wa read in. hopefully that makes some sense =/
im pretty sure that the problem is in one of the loops of lookup function. (while or if else)
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void add(string);
void lookup(string);
int main(){
ifstream a;
string name, choice, name2, email, longstring;
cin >> choice;
if (choice == "lookup"){
cin >> name;
lookup(name);
}
else {
cin >> name >> name2 >> email;
longstring = name + " " + name2 + " " + email;
add(longstring);
}
return 0;
}
void add(string longstring){
ofstream a;
a.open("phonedir");
a << longstring;
}
void lookup (string name){
ifstream a;
string line;
a.open("phonedir");
while (!a.eof()){
getline(cin, line);
if (line.find(name))
cout << line;
else
"";
}
}