安全的CRT字符串功能 [英] Secure CRT string functions

查看:103
本文介绍了安全的CRT字符串功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将我们的VS6 MFC项目转换为VS2010,并不断获得:

I''ve just converted our VS6 MFC project to VS2010 and keep getting:

warning C4996: ''fscanf'': This function or variable may be unsafe.



等等.

但是,当我尝试定义_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES时,它要么什么都不做,要么告诉我它已被定义(在crtdefs.h中).
我真的不想在所有地方都定义它,所以我的StdAfx.h是这些定义的正确(也是最好的)地方吗?



et cetera.

However, when I try to define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES it either doesn''t do anything, or tells me it is already defined (in crtdefs.h).

I don''t really want to have to defin it all over the place so is my StdAfx.h the correct (and best) place for these definitions?

推荐答案

这可能会回答您的问题...
http://msdn.microsoft.com/en-us/library/ms175759%28v = VS.100%29.aspx [ ^ ]
This may answer your question...
http://msdn.microsoft.com/en-us/library/ms175759%28v=VS.100%29.aspx[^]


请参阅:http://msdn.microsoft.com/zh-CN/library/6ybhk9kc.aspx [
预处理程序无法自动将安全版本fscanf_s替换为fscanf,因为安全版本需要不同的参数.

您必须自己修复fscanf调用,或者决定忽略这些警告.

至于定义_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES的位置,我可以在编译器命令行中或顶部的StdAfx.h中进行.
See: http://msdn.microsoft.com/en-us/library/6ybhk9kc.aspx[^]

"The main difference between the secure functions (with the _s suffix) and the older functions is that the secure functions require the size in characters of each c, C, s, S and [ type field to be passed as an argument immediately following the variable."

There is no way the preprocessor can automatically substitute the secure version fscanf_s for fscanf because the secure version requires different parameters.

You''ll have to either fix the fscanf calls yourself or decide to ignore those warnings.

As for where to define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES, I would either do it on the compiler command line, or in StdAfx.h at the top.


这篇关于安全的CRT字符串功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆