I don't know that this is more efficient, it is the same logic, with a few adjustments. No use of eof() - though in the original code it was ok. No need to use a dot to end a string. Note the mixing of cin >> and cin.getline often causes problems. Here I used a function empty() to remove the trailing newline '\n' left behind after the previous cin >>.
i use dot to end input to remove any sort of error as i like to mix cin and cin.getline( errors like infinite output , error in reading, reading input as a single character).
I like how you used the condtion of reading the file inside while loop
i use dot to end input to remove any sort of error as i like to mix cin and cin.getline
That approach might add more problems than it solves. At any rate, it is risky.
Suppose at the prompt "Enter name" the user enters something like
Bjarne
Stroustrup
.
Or perhaps
A
r
t
h
u
r.
Your version would accept the whole thing, complete with newlines as part of the name. I can think of circumstances where this type of user input might be useful, but I'm not convinced that this is one of them.
Whatever you decide, you should at least be familiar with more conventional alternatives such as the approach I used.