+ 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".

27th Dec 2017, 9:30 AM
CuriousCI
CuriousCI - avatar
20 Antworten
+ 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/
27th Dec 2017, 10:59 AM
Hatsy Rei
Hatsy Rei - avatar
+ 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.
27th Dec 2017, 10:50 AM
Hatsy Rei
Hatsy Rei - avatar
+ 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.
27th Dec 2017, 11:05 AM
Hatsy Rei
Hatsy Rei - avatar
+ 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.
27th Dec 2017, 9:52 AM
Calviղ
Calviղ - avatar
+ 2
then I should use stdio?
27th Dec 2017, 10:07 AM
CuriousCI
CuriousCI - avatar
+ 1
game user interface.
27th Dec 2017, 10:03 AM
CuriousCI
CuriousCI - avatar
+ 1
iostream
27th Dec 2017, 10:05 AM
CuriousCI
CuriousCI - avatar
+ 1
Ok, I am using an interface similar to the windows' command prompt.
27th Dec 2017, 10:09 AM
CuriousCI
CuriousCI - avatar
+ 1
Nope. It's a dungeon game.
27th Dec 2017, 10:11 AM
CuriousCI
CuriousCI - avatar
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.
27th Dec 2017, 11:01 AM
Timon Paßlick
0
Ok. Then it's somehow critical.
27th Dec 2017, 11:06 AM
Timon Paßlick
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.
27th Dec 2017, 11:09 AM
Timon Paßlick
- 1
Is the value entered into the debugging console or into your games user interface?
27th Dec 2017, 10:02 AM
Timon Paßlick
- 1
Which library are you using?
27th Dec 2017, 10:04 AM
Timon Paßlick
- 1
iostream is used for the debugging console, not for graphical windows.
27th Dec 2017, 10:06 AM
Timon Paßlick
- 1
stdio is just older, it's also for the text console.
27th Dec 2017, 10:08 AM
Timon Paßlick
- 1
What does your game look like?
27th Dec 2017, 10:08 AM
Timon Paßlick
- 1
Is it a text adventure?
27th Dec 2017, 10:10 AM
Timon Paßlick
- 1
@Hatsy Rei Why is getch() bad practice and how is getchar() better?
27th Dec 2017, 10:55 AM
Timon Paßlick
- 1
@Hatsy Rei Why is this considered bad practice?
27th Dec 2017, 10:56 AM
Timon Paßlick