the new line character after you pressed ENTER is present in buffer. So the next read with getline reads empty string.
You should remove or read the new line character before getline will be executed.
I appreciate for all your interest. I tried each of your suggestions but I couldn't work it because I'm unexperienced.
Finally I found smt in the tutorial and it works using stringstream.But I don't know the reason why it is work like this.Any idea?
This is not an unusual problem. Can't we just create some functions that handles new lines "correctly" that the beginners can use? Here is my try.
Hijacking a thread for that is probably not a good idea. (And it won't work in the general case.)
@langdon:
A stringstream (you should probably use an istringstream here) acts like an input or output stream. The content of the istringstream is the string you initialize it with. The reason you don't experience the same problems with the stray newline is because you're using line oriented input via getline which doesn't leave the trailing newline in the input stream.