Why getch() is not working in Visual Studio 2008?

给你一囗甜甜゛ 提交于 2019-12-10 23:39:48

问题


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

error C3861: 'getch': identifier not found . 

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?

Code:

#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;

}

回答1:


use _getch()

e.g.

#define getch() _getch()

sample

#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;

}



回答2:


You can use as well as

#include<iostream>

    int main()
{

system("pause");
return 0;
}


来源:https://stackoverflow.com/questions/16405936/why-getch-is-not-working-in-visual-studio-2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!