I am new to programming. And i am learning through tutorials and making little programs myself.But i've faced a problem.I am using Code::Blocks to program in C++ but i cannot find a way to detect a key press, exept with getch() but i dont like getch sooo..Can somebody help me out.I've look through a ton of forum in about this topic but i was never able to find a clear anwser and something that actually works. Thanks! :)
Assuming you're running on Windows and you don't want to use conio functions then you should investigate either the Windows API, or perhaps the PDCurses library.
The only reason it is "conformant" to ISO C++ is because it uses the leading underscore character to denote that the function is "implementation defined". This function is still not a standard C or C++ function.
That link: https://msdn.microsoft.com/en-us/library/ms235390.aspx is really only telling you that the POSIX version of the function is depreciated. Really it is telling you that the whole POSIX subsystem was depreciated by Microsoft since Windows XP.
Yes, they appear, but it is also a very misleading statement. These functions are not defined in either the C nor the C++ standard, therefore they are not standard functions, but the standard does allows implementations to define their own functions to "enhance" their product. So by renaming the function to "_kbhit()" or "_getch()" you now have functions that qualify as an implementation defined function.
From one of the C++14 draft standards:
17.6.4.3.2 Global names [global.names]
Certain sets of names and function signatures are always reserved to the implementation:
— Each name that contains a double underscore _ _ or begins with an underscore followed by an uppercase letter (2.12) is reserved to the implementation for any use.
— Each name that begins with an underscore is reserved to the implementation for use as name in the global namespace.
well there's only one thing you can do then, get in touch with Microsoft and let them know rather than moaning about it here
Why should I "get in touch with Microsoft"? You're the one that doesn't understand the difference between a "conformant" function and a "standard" function.
At the very outset I said
Microsoft claims
, did I not? Now which bit of this don't you understand
Ah, so then you admit that you're also being very misleading? If you knew before hand that it was a misleading statement you wouldn't have propagated the statement, would you?
But i want to make it for exaple when i press the letter 'g' it then activates
You stated you didn't want to use getch()/_getch() so have you investigated the Windows API or PDCurses? Or did you decide that using getch() would be acceptable?