为什么getch()在Visual Studio 2008中不起作用? [英] Why getch() is not working in Visual Studio 2008?

查看:352
本文介绍了为什么getch()在Visual Studio 2008中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码在MinC的DevC ++中可以正常工作,但是Visual Studio 2008会这样:

Below code works in DevC++ with MinGW works flawlessly but Visual Studio 2008 spits this:

error C3861: 'getch': identifier not found . 

如果不可能,我该怎么办才能接受getch()?除了getch()之外,还有其他方法可以用来暂停屏幕吗?

What can I do to accept getch() if this is not possible is there an alternative to getch() that I can use to pause the screen?

代码:

#include <stdio.h>
#include <conio.h>

int main(void){

    char str[] = "This is the end";
    printf("%s\n", str);
    getch();   //I tried getchar() also still does not work
    return 0;

}

推荐答案

使用例如

#define getch() _getch()

样本

#include <stdio.h>
#include <conio.h>

#ifdef _MSC_VER
#define getch() _getch()
#endif

int main(void){

    char str[] = "This is the end";
    printf("%s\n", str);
    getch();
    return 0;

}

这篇关于为什么getch()在Visual Studio 2008中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆