Answer the question
In order to leave comments, you need to log in
C++: Why does getch return -1 before I press any key?
Actually, subject. Here is the code and its output?
#include <stdio.h>
#include <iostream>
#include <curses.h>
#include <ncurses.h>
using namespace std;
int main(){
int code;
code = getch();
std::cout << code;
}
-1
------------------
(program exited with code: 0)
Press return to continue
Answer the question
In order to leave comments, you need to log in
do {
code = getch();
}
while(code == -1);
std::cout << code;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question