I'm creating a basic console application in C/C++.
In the following example I'm repeatedly writing some char to the console with a 50ms delay and I want it to exit the program when I hit a key.
#include "pch.h"
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <conio.h>
int PauseRet(int iDuree) {
unsigned int uiTemps = GetTickCount();
int iVal = 0;
do {
if (_kbhit()) {
iVal = _getch();
}
} while ((GetTickCount() - uiTemps) < (unsigned int)iDuree);
return iVal;
}
int main()
{
char c = 0;
int iTempo = 50;
while (true) {
putchar('a');
c = PauseRet(iTempo);
if (c) {
return 0;
}
}
}
My problem is that in my project it goes into the condition if(c){...
only when I put a break point here:
if (_kbhit()) {
<BREAKPOINT> iVal = _getch();
}
I'm using visual studio 2017.
I've tried this code on another PC in a new project and I didn't had any problem
I believe this has something to do with my project settings.