Sigh, another one of these. But please don't think I am talking about you personally, it is just that this appears so often here. I just don't know why people can't find it already in Google. I'll try a search myself. I'll try "c++ console no prompt"...
Ok, 5th result
http://stackoverflow.com/questions/2209135/safely-prompt-for-yes-no-with-cin is relevant but too obscure to decipher in this context.
First page gone by, no direct hit. I'll try with "c++ console skips input"...
OK, 4th hit was good enough:
http://www.dreamincode.net/forums/topic/187571-cingetline-making-the-console-skip-a-line/. It took me some 12 minutes. Not too bad. Multiply that by 3 just to be on the safe side and you still have a decent time span, wouldn't you say?
Anyway, I never remember exactly how the whole thing goes because I don't do console apps, so pardon if my solution here is not 100% spot on:
This happens because the newline char is lingering on inside the keyboard input buffer, which is the source of data for 'cin'. What does this mean? It means that the getline() function will find it right away without you having to type a thing, and therefore "skipping" the prompt.
Fixes:
1. cin.sync() I believe does the trick pretty well. You should call it every time after a call to the extraction operator (operator>>).
2. I think cin.ignore() will ignore one char, so if the next char in line is the newline char, this works too.
3. If you want to ensure more chars are ignored, you can use the overloaded method that takes the count of chars to ignore, plus an escape char. I think it is
cin.ignore(std::numeric_limits<streamsize>::max(), '\n');
. To be able to use std::numeric_limits, you need to #include <limits>.
If one of the above doesn't work, it could be because cin's fail bit may be on. Call cin.clear() before the solution you picked above in order to restore cin to a good state.