In this code:
char ch;
while(cin.get(ch))
{
std::cerr<<"got ch:"<<ch<<std::endl;
}
Why do I have to hit enter before the "got ch:" is printed on screen ?
Is there a way to have characters echoed right after they are typed ?
See Canonical vs Non-canonical Terminal Input for a lot of details.
Yes, by default you have to enter return before any data is made available.
Yes, there are ways to use non-canonical input so that characters are available as soon as they are entered. However, the mechanisms for obtaining that behaviour are radically different between Windows and Unix-based systems.