2

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 ?

steviekm3
  • 905
  • 1
  • 8
  • 19

1 Answers1

5

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.

Community
  • 1
  • 1
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278