2013-05-06 44 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

相關問題