Hey all. Been reading through this and I'm really surprised that nobody mentioned clearing the input buffer. It's pretty darn likely that "getchar()" or anything else besides a "cin" won't actually wait for a user's input because there is garbage sitting in the input buffer.
You can very easily use getchar() by first clearing the input buffer. DON'T use loops or anything. Seems silly... Just clear the buffer. You should be clearing the buffer before and after you use any "getline" statement anyway, for safety reasons.
Code:
#include <iostream>
using std::cout; // Specify only the functions you're going to use
using std::cin; // to cut down on file sizes
int main()
{
//Stuff 'n things
cout << "Press <ENTER> to quit...\n";
cin.ignore( cin.rdbuf()->in_avail() );
getchar();
cin.clear();
cin.ignore( cin.rdbuf()->in_avail() );
return 0;
}
Granted, this doesn't answer the original question of accepting ANY character, because the input stream automatically recognizes a carriage return (or ENTER key) as the terminating character of the string. So you have to hit ENTER at some point. But at least this method is simple and works efficiently.
Hope that helps a bit. Cheers! :-)