MSVC build errors > C4996
C4996: function may be unsafe or deprecated
warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead.
MSVC marks some C runtime functions as unsafe or deprecated. C4996 is a warning, but it stops the build when SDL checks (/sdl) or Treat Warnings As Errors are on, as in new projects.
Causes and fixes
- A string function can overflow its buffer. Prefer
std::string, or the bounded functions such asstrcpy_sandsnprintf. - A POSIX name is used. Functions such as
openorstrduphave ISO C++ names with an underscore:_open,_strdup. - Portable code must keep the standard functions. Define
_CRT_SECURE_NO_WARNINGSin the project's preprocessor definitions, for that project only, rather than disabling C4996 for everything: it also reports your own[[deprecated]]functions.
Fix C4996 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: C2065. See all guides.