2013-05-06 48 views
1

下面的代码在DEVC++使用MinGW完美的作品,但Visual Studio 2008中吐出这样的:为什么getch()在Visual Studio 2008中不起作用?

error C3861: 'getch': identifier not found . 

我能做些什么来接受的getch()如果这是不可能是那里参考getch(替代),我可以用来暂停屏幕?

代码:

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

} 
+0

如何[GETC()(http://msdn.microsoft.com/en-us/library /5231d02a(v=vs.90).aspx)? – 2013-05-06 19:40:38

+0

错误C2660:'getc':函数不接受0个参数 – Lyrk 2013-05-06 19:44:11

+0

您必须将它传递给您想要读取的流,在本例中为'getc(stdin)'。 – 2013-05-06 19:45:45

回答

5

使用_getch()

例如

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

} 
+0

我应该包含哪个标题? – Lyrk 2013-05-06 19:45:42

+0

@ user1939432'#include '。 'getch()'没有下划线也在那里声明,至少在Visual Studio的新版本中。 – 2013-05-06 19:46:54

+0

@ user1939432'#include '。 '#define getch()_getch()'代替了方便。 – BLUEPIXY 2013-05-06 19:47:57

0

您可以使用以及

#include<iostream> 

    int main() 
{ 

system("pause"); 
return 0; 
} 
+0

我使用系统(“暂停”)读取;不是一个好主意。 – Nditah 2017-10-16 10:03:02

相关问题