将#include <vector>添加到MFC项目</vector>时出现警告C4995

时间:2015-03-25 03:59:12

标签: c++ stl mfc

我试图将#include <vector>添加到我的MFC项目中。它编译,但我得到以下警告(只是其中一些,实际列表更长):

1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\cstdio(49) : warning C4995: 'gets': name was marked as #pragma deprecated
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\cstdio(53) : warning C4995: 'sprintf': name was marked as #pragma deprecated
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\cstdio(56) : warning C4995: 'vsprintf': name was marked as #pragma deprecated
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\cstring(22) : warning C4995: 'strcat': name was marked as #pragma deprecated
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\cstring(23) : warning C4995: 'strcpy': name was marked as #pragma deprecated
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\cwchar(36) : warning C4995: 'swprintf': name was marked as #pragma deprecated
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\cwchar(37) : warning C4995: 'vswprintf': name was marked as #pragma deprecated
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\cwchar(39) : warning C4995: 'wcscat': name was marked as #pragma deprecated
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\cwchar(41) : warning C4995: 'wcscpy': name was marked as #pragma deprecated

我可以通过这样做来保持沉默:

#pragma warning(push)
#pragma warning(disable: 4995)
#include <vector>
#pragma warning(pop)

但我很想知道为什么图书馆会引起这些警告?除了抑制警告之外,还有更好的解决方法吗?

1 个答案:

答案 0 :(得分:0)

此警告表示已标记为已过时的功能,在将来的版本中可能不再支持该功能。

所以你可以有两种方法来处理它:首先是你使用的方式,用pragma标记它,或者你可以使用它们的安全版本。

例如,Strcpy有一个名为StringCchCopy / StringCbCopy的相应函数,get有get_s。您可以从MSDN找到它们。

祝你好运。 :)