What prevents your program from compiling is the following:
1) close doesn't need arguments - change both
a.close("phonedir"); with
a.close(); .
2)
else "" ; doesn't make sense. Maybe you wanted to write
else cout << ""; .
Said that, your code presents at least one
big problem and two minor ones.
The big one: you call add function recursively (why?) and you don't set a base case. This is bad. Delete that recursive
add(longstring); line and put ther a simpler and healtier
a << longstring;
The "minor" ones:
1)
getline(cin, line); would likely be
getline(a, line); (as you are searching a)
2) You still probably need to open your ofstream in append mode in your add function.
EDIT:
printed out what I typed in, lovely
that has to do with minor problem #1