MSVC: error C2065: 'x': undeclared identifier
Visual C++ met a name it has not seen declared — a typo, a missing header or namespace, or use outside its scope.
C2065: undeclared identifiererror C3861: identifier not founderror C2039 is not a member oferror C2143: syntax error: missing ';' before Meaning
This is MSVC's counterpart of GCC's "was not declared in this scope". With precompiled headers a missing #include "pch.h" first line, a header only included in some configurations, and a wrong _MSC_VER or #ifdef guard are extra causes. Often followed by C3861 ("identifier not found") for functions.
Common causes
- Missing
#includeof the header that declares the name - Missing
std::qualifier orusingdeclaration - Typo or wrong case in the name
- Variable declared in an inner scope or later in the file
#include "pch.h"missing as the first line of a .cpp in a project with precompiled headers
⚡ Quick fix
- Include the right header and qualify the name
- Put
#include "pch.h"first in every .cpp if the project uses precompiled headers - Check spelling and scope
Detailed fix by platform
Visual Studio
- Hover the red squiggle → Quick Actions suggests the missing include
- In Project Properties → C/C++ → Precompiled Headers, check "Use (/Yu)" and the header name
Windows
- For Windows API names such as
CreateFile, include<windows.h>and defineWIN32_LEAN_AND_MEANif you want a smaller header set
Code examples
Missing header and namespace
#include <string>
#include <iostream> // without this: error C2065: 'cout': undeclared identifier
int main() {
std::string name = "Ada";
std::cout << name << "\n";
}How to diagnose
- Header — Which header declares it?
- Scope — Used where it is visible?
- PCH — Precompiled header include first?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- AddressSanitizer: heap-buffer-overflow C/C++: ==ERROR: AddressSanitizer: heap-buffer-overflow on address — READ/WRITE of size N
- AddressSanitizer: heap-use-after-free C/C++: ==ERROR: AddressSanitizer: heap-use-after-free on address — memory used after delete/free
- C4996 MSVC: error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead
Most viewed in C/C++
- terminate called after throwing an instance of C++: terminate called after throwing an instance of 'std::out_of_range' — what(): vector::_M_range_check
- double free or corruption C/C++: free(): double free detected / double free or corruption (out) — Aborted (core dumped)
- undefined reference to C/C++: undefined reference to `function' — collect2: error: ld returned 1 exit status
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026