微软Visual Studio 2017 - getch()问题 [英] Microsoft visual studio 2017 - getch() problem
问题描述
#include
void main()
{
printf( Hello C跨度>);
getch(); // 此处使用getch()
}
#include
#include
void PrintMessage( void )
{
printf( Hello C);
}
int main()
{
PrintMessage();
_getch(); // 此处使用getchch()
}
我在Microsoft Visual Studio 2017中执行它。你可以向我解释一下编译器在执行命令getch()时所需要的更改。
我尝试了什么:
这两个程序都有输出。但由于我处于初学者阶段,我需要在一个命令中了解这一变化。
你需要在你的文件的顶部:
#include < conio.h >(代码中#include的文件名似乎已经消失,但由于printf我假设一个是stdio.h所以你不会有conio.h)。
< blockquote>与Visual Studio无关, getch
和 _getch
都是C库调用。第二个版本是C运行时库的最新版本中的首选版本;请参阅 _getch,_getwch | Microsoft Docs [ ^ ]。
是的,谢谢Richard的回答。我也对此做了一些研究,发现通过在标题上面写上#define _CRT_SECURE_NO_WARNINGS,它会删除程序中的这些错误。
#include
void main()
{
printf("Hello C");
getch(); //Here getch() is used like this
}
#include
#include
void PrintMessage(void)
{
printf("Hello C");
}
int main()
{
PrintMessage();
_getch(); // here getchch() is used like this
}
I am executing it in Microsoft Visual studio 2017. Can you please explain to me this change that is required by the compiler in executing the command "getch()".
What I have tried:
Output is coming for both the programs. But since i am in beginners stage, i need to know about this change in one command.
You'll need this at the top of your file:
#include <conio.h>(The file name of the one #include in your code seems to have disappeared but because of the printf I assume that one is stdio.h so you won't have conio.h already).
Nothing to do with Visual Studio,getch
and_getch
are both C library calls. The second version is the preferred one in the latest versions of the C runtime libraries; see _getch, _getwch | Microsoft Docs[^].
Yes, thanks for the answer Richard. I also did some research on this and found out that by writing " #define _CRT_SECURE_NO_WARNINGS " on top of the headers, it removes such errors in the programs.
这篇关于微软Visual Studio 2017 - getch()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!