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
  • 855
  • 1
  • 7
  • 16

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
  • 698,132
  • 130
  • 858
  • 1,229