I took my first ‘fundamentals of programming’ lab session at uni today. One thing struck me as odd, though: the use of while(! _kbhit()) from conio.h (which I’m sure is a C unit?) to ‘pause’ the console output.
Is this the best way to do this? What do I need to watch out for when using it? Is my tutor absolutely bonkers? I only ask because it seemed like a bit of a dirty hack and I’ve never seen it before in any of the C++ code snippets I’ve looked at.
Marked question as homework because it’s school related, but not actually a homework task. If this question is better off as CW, let me know.
A very quick (and easy to remember) way of doing this is to use
getchar:You may have to press Return after entering your char, depending on
stdin‘s buffering mode. You can probably usesetvbufto fix that, but personally I just always press Return.You may also be using C++ iostreams. In that case, you’ll want to call this somewhere: