MSVC build errors > C2065
C2065: undeclared identifier
error C2065: 'cout': undeclared identifier
The compiler met a name it has no declaration for at that point of the file.
Causes and fixes
- The name is misspelled. C++ is case-sensitive:
Countandcountare different names. - The header that declares it is not included. Include it in the file that uses the name, instead of relying on another header to include it.
- The name lives in a namespace. Write
std::cout, or add ausingdeclaration. - The declaration is in another scope, or comes later. A variable declared inside a block or a loop does not exist after it, and a name must be declared before its first use.
- Code comes before the precompiled header. With precompiled headers, everything before
#include "pch.h"is ignored. Make it the first line of the file. - The declaration is excluded by the preprocessor. Check the
#ifor#ifdefaround it and the preprocessor definitions of the configuration.
Fix C2065 with CppPilot
CppPilot reads the error, your code, and the project settings Visual Studio evaluates for the active configuration, then explains which of these causes applies. Choose Fix and the AI corrects it; CppPilot rebuilds the project and checks that the error is gone. Every change appears in Visual Studio for your approval.
Let the AI fix it in Visual Studio
CppPilot is a free extension that explains and fixes MSVC build errors with Codex, Claude, or CppPilot Cloud.
Related errors: C2039, C4430, C1083, C1010. See all guides.