Tag Archives: MFC error boiled down

Error C2065 ‘cout’: undeclared identifier

1 [problem background] Error C2065 appears in C++/MFC, that is, XXX is not defined, and the XXX you use is the base class library, do you think it may not exist?Except, of course, for your spelling mistakes, which I won’t discuss.
2 [Analysis] Check that the basic class library of VS/VC has no problem in loading and platform setting; This is usually due to placing certain header files in front of stdafx.h header files.
3 [Example of solution]
3.1 Question of the above title: Error C2065 ‘cout’: Undeclared Identifier. This is due to placing the header file “iostream.h” in the implementation file as follows:
// The following is the implementation of XXXX. CPP
# include & lt; iostream.h>
# include “stdafx. H”
/ /…
Int xxx_fun ()
{
STD: : cout< < somevar< < std::endl;
}
3.1.1 [Results] The above error C2065 will occur;
3.2 [Modification method] Put stdafx.h in the first place, and do not let the words of other header files come before it.
// The following is the implementation of XXXX. CPP
# include “stdafx. H”
# include & lt; iostream.h>
/ /…
Int xxx_fun ()
{
STD: : cout< < somevar< < std::endl;
}
3.2.1 [Results] There will be no Error C2065 above;
3.3 [Summary] If the library and platform are correctly configured, the above methods can be basically solved. This is a small mistake that is easy to overlook because we don’t usually feel the need to prioritize header files. Well, the devil is in the details, and the difference between first and second place in the arena is sometimes 0.001 seconds, so don’t make any small mistakes.