I am writing a program and this error crashes:

error C2065: 'cout': undeclared identifier;

What could be the reason?

Here is the program:

#include <iostream> using namespace std; #include "stdafx.h" void main() { int a, b ; cout << "Enter f-st n-bre" ; cin >> a ; cout << "second"; cin >> b ; cout << "sum is " << a+b << '\n'; } 
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

The header that is 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 goes before this inclusion is ignored.

Therefore, to solve your problem, you need to make #include "stdafx.h" first line in the file.