我有以下代碼爲什麼VC++ 2010 Express在這個程序中不需要stdio.h但是gcC++呢?
#include <iostream>
using namespace std;
void WaitForEnter()
{
while(1)
{
if('\n' == getchar())
{
break;
}
}
return;
}
int main()
{
cout<< "Press Enter to Exit... ";
WaitForEnter();
}
這將編譯上的Microsoft Visual C++ 2010 Express和做什麼,我的預期。在使用code :: blocks和gcC++ 4.7的Ubuntu上,構建失敗,出現以下error: 'getchar' was not declared in this scope.
如果我添加行,程序將編譯並以預期行爲運行。爲什麼此程序使用MVC++ 2010 Express進行編譯,而不使用stdio.h
,但不適用於Ubuntu上使用gcC++ 4.7的code :: blocks。
您是否使用預編譯頭文件(即'stdafx.h')? –
@Jesse好我不熟悉預編譯頭文件,只是做了一個快速搜索,是的,我正在使用它們,我應該關閉它們嗎? – newToProgramming
我不認爲visual studio會讓你編譯,除非你包括stdafx.h – Rhexis