How can i make a function that stops the program when a key is pressed?(the function needs to run as a thread).I tried this but doesn't work
  _getch() == true;
  if(_getch() == true){
    exit(0);
  }
How can i make a function that stops the program when a key is pressed?(the function needs to run as a thread).I tried this but doesn't work
  _getch() == true;
  if(_getch() == true){
    exit(0);
  }
 
    
    You can use the ncurses library,
#include <ncurses.h>
... 
initscr();          /* Start curses mode   */
getch();            /* Wait for user input */
endwin();           /* End curses mode     */
...
You can find the documentation related to it at the NCURSES Programming HOWTO
The answer exists at askubuntu.
The following works on windows and linux/unix:
#include <iostream>
...
std::cout << "Press \'Return\' to end." << std::endl;
cin.sync(); // instead of flush()
std::cin.get();
The first
std::cin.sync()clears the input que, the next command waits for an input.
