20 Answers
New Answer20 Answers
New Answergetch() and other functions which originate from conio.h header should be avoided, because conio, as stated in Wikipedia, "is a C header file used mostly by MS-DOS compilers to provide console input/output. It is not part of the C standard library or ISO C, nor is it defined by POSIX." In layman terms, it is OS dependent, and the header itself is ancient and not supported by all C/C++ compilers. getchar() on the other hand, is defined in the C++ standard. http://www.cplusplus.com/reference/cstdio/getchar/
https://www.sololearn.com/discuss/210329/?ref=app getch() used to be the idea, but then whoever uses this will be banished to the deepest layer of hell, tormented by demons and ghouls for the rest of their lives. Seeing that this is new to you, you can give it a try, but again, beware. After trying it out, look at getchar(), which isn't the exact replacement for getch(), but is 'legal' and should do the job just fine. All is included in this thread.
The problem is, it can't. Linux and OSX wouldn't compile getch(), and as far as I am concerned, the program will break if executed on those platforms.
Instead of putting "C++" as a topic, you should set appropriate topic like "Program continue run without pressing enter", would make you find the solutions faster.
Sometimes our community is ridiculous. ( : If something can't be ported to a digital oven clock, you're cursed forever when you use it. When something can be compiled with VS and Code::Blocks and used with Windows 7+, Linux and OSX, that's usually sufficient.
I have a trick to use getchar() without displaying. But that's just in case Linux and OSX have something like cls. Then you can clear the screen after every input and render everything again.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message