getch()和_getch()之间的区别 [英] Difference between getch() and _getch()
问题描述
在conio.h头文件中定义的两个函数之间的区别 -
What is the difference between the two function that are defined in the conio.h header file-
getch()和_getch()。
getch() and _getch().
在decalaration中有不同吗?
Is there a difference in the decalaration? Or is it simply a difference due to updated standards?
推荐答案
这是Microsoft几年前决定的一部分,更加严格地解释C ++标准。它说,全局命名空间中以下划线开头的所有名称都保留供实现使用 。这意味着 getch
不是保留名称,但 _getch
是。
It is part of a decision by Microsoft a couple of years ago to interpret the C++ standard more rigidly. It says that all names in the global namespace which start with an underscore are reserved for use by the implementation. This means that getch
is not a reserved name, but _getch
is.
所以,微软认为这个函数和所有其他的POSIX函数是由实现提供的,让我们重命名它们前面加一个下划线,所以我们可以把它保留在保留部分全局命名空间,这样,用户提供的函数就不会发生名称冲突。
So Microsoft figured that "this function, and every other POSIX function, is kind of supplied by the implementation. Let's rename them by prepending an underscore, so we're able to keep it inside the "reserved" part of the global namespace. That way, there's no chance of name clashes with user-supplied functions.
你可以说这些是好的意图,在打破POSIX代码,我不知道他们真正的动机是什么,但最终的结果是根据微软, getch
已弃用,你应该使用 _getch
。
You could say that these are good intentions, or that it's just an evil attempt at breaking POSIX code. I don't know what their true motivation was, but the end result is that according to Microsoft, getch
is deprecated, and you should use _getch
instead.
这篇关于getch()和_getch()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!