我有以下代码
#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. 如果我添加该行#include "stdio.h",程序将编译并以预期的行为运行。为什么这个程序stdio.h在 Ubuntu 上使用 MVC++ 2010 Express 编译,但没有使用 gcc++ 4.7 的 code::blocks。