+ 1
C++ Continuing program once entered a value without pressin enter
I am creating a rpg game on c++ (using DEV c++), and I am searching a way, that, once entered a value, the program continues without pressing "Enter".
20 Respostas
+ 6
getch() 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/
+ 5
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.
+ 4
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.
+ 3
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.
+ 2
then I should use stdio?
+ 1
game user interface.
+ 1
iostream
+ 1
Ok, I am using an interface similar to the windows' command prompt.
+ 1
Nope. It's a dungeon game.
0
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.
0
Ok. Then it's somehow critical.
0
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.
- 1
Is the value entered into the debugging console or into your games user interface?
- 1
Which library are you using?
- 1
iostream is used for the debugging console, not for graphical windows.
- 1
stdio is just older, it's also for the text console.
- 1
What does your game look like?
- 1
Is it a text adventure?
- 1
@Hatsy Rei Why is getch() bad practice and how is getchar() better?
- 1
@Hatsy Rei Why is this considered bad practice?