【解決!】Visual Studio(Visual C++)でerror C4996やwarning C4996が出る

Visual C++で開発中にerror C4996またはwarning C4996が出て鬱陶しくなることがあります。

しかも、error C4996、warning C4996はC言語的には問題がないはずなのに出るんですよね。

1>c:\consoleapplication1\consoleapplication1.cpp(19): error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\string.h(112) : 'strcpy' の宣言を確認してください。
エラー 1 error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. c:\consoleapplication1\consoleapplication1.cpp 19 1 ConsoleApplication1
1>c:\consoleapplication1\consoleapplication1.cpp(19): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\string.h(112) : 'strcpy' の宣言を確認してください。
警告 1 warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. c:\consoleapplication1\consoleapplication1.cpp 19 1 ConsoleApplication1

これらは、セキュリティ強化バージョンの関数を使わず、従来のセキュリティに問題のある関数を使っている場合に出るメッセージです。

ただ、場合によってはセキュリティ強化バージョンの関数を使えないこともあります。

そんなときは、C4996を抑制することで、この鬱陶しいメッセージを消すことができます。

C4996を抑制する方法

[SDLチェック]をいいえにして、[特定の警告を無視する]に4996を入力すればOKです。

sdl3.png

4996.png

ただし、これらの設定をする前に本当にerror C4996、warning C4996を無視していいのか確認してください。

セキュリティの観点から言うと無視せずに、セキュリティ強化バージョンの関数を使った方がいいですから。