So, I have this question. Why does cout throws
error C2065: \'cout\' : undeclared identifier
I am using Visual Studio 2012 as an IDE and I
#include "iostream"
should be
#include
Quoting from this post:difference-between-iostream-and-iostream-quotes-in-include
By courtesy of @Jerry Coffin's answer:
When you use < >, the compiler only looks in the system-designated directory/directories (e.g., whatever you've set in the include environment variable) for the header.
When you use " ", the compiler looks in the local directory first, and if that fails, re-searches just like you'd used < >. Technically, (i.e., according to the standard) that doesn't have to be the "local" directory, but that's how it works in essentially every compiler of which I'm aware).
EDIT:
However, the root cause is that stdafx.h
is a precompiled header. Visual C++ will not compile anything before the #include "stdafx.h"
in the source file, unless the compile option /Yu'stdafx.h'
is unchecked (by default); it assumes all code in the source up to and including that line is already compiled. However, it is still better to use <>
with iostream
not to confuse reader of the code.