我有以下代码为什么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