I am writing a program and the following error crashes:
error C2065: ‘cout’: undeclared identifier;
What could be the reason?
Here’s the program:
# include & lt; iostream & gt;
using namespace std;
#include "stdafx.h"
void main ()
{
int a, b;
cout & lt; & lt; "Enter f-st n-bre";
cin & gt; & gt; a;
cout & lt; & lt; "second";
cin & gt; & gt; b;
cout & lt; & lt; "sum is" & lt; & lt; a + b & lt; & lt; '\ n';
}
Answer 1, authority 100%
The header used for precompiled headers in Visual Studio should always be the first line in the file it is included in. This requirement appeared because everything that comes before this inclusion is ignored.
Therefore, to solve your problem, you need to make #include "stdafx.h"
the first line in the file.