0

I want to accept several characters in my input and process them as they are being typed. I would use it like that:

char c;
string line;
    
while((c = getchar() != '.')) 
    line += c;   

cout << line << endl;

The expected behavior would be to stop getting inputs as soon as a '.' char is typed, without the need for the return button to be pressed.

Dan
  • 127
  • 9

1 Answers1

0

The solution could be to use the ncurses library which allows you to open a graphic window of a terminal and to have getch() type functions but which does not block your program if you allow it before (Stack exemple here). Then it is possible to constantly check if a '.' was pressed and performed N actions at the same time. I hope I was able to help you !

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 10 '22 at 14:33