Tuesday, May 22, 2012

Why doesn't VC++ 2010 Express require stdio.h in this program but gcc++ does?

I have the following code



#include <iostream>

using namespace std;

void WaitForEnter()
{
while(1)
{
if('\n' == getchar())
{
break;
}
}
}

int main()
{
cout<< "Press Enter to Exit... ";
WaitForEnter();
}


This compiles on Microsoft Visual C++ 2010 Express and does what I expected. On Ubuntu using code::blocks and gcc++ 4.7 the build fails with the following error: 'getchar' was not declared in this scope. If I add the line #include "stdio.h", the program compiles and runs with the expected behavior. Why does this program compile using MVC++ 2010 Express without stdio.h but not for code::blocks with gcc++ 4.7 on Ubuntu.





No comments:

Post a Comment