<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="http://itecfun.com/extern.php?action=feed&amp;tid=3163&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[个人知识管理站 / warning C4996: 'strcpy': This function or variable may be unsafe. Cons]]></title>
		<link>http://www.itecfun.com/viewtopic.php?id=3163</link>
		<description><![CDATA[warning C4996: 'strcpy': This function or variable may be unsafe. Cons 最近发表的帖子。]]></description>
		<lastBuildDate>Mon, 15 Jun 2015 10:08:32 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[warning C4996: 'strcpy': This function or variable may be unsafe. Cons]]></title>
			<link>http://www.itecfun.com/viewtopic.php?pid=3318#p3318</link>
			<description><![CDATA[<p>使用VS2005以上版本（VS2005、VS2008、VS2010）编译在其他编译器下正常通过的C语言程序，你可能会遇到类似如下的警告提示：<br /> 引用内容<br />warning C4996: &#039;strcpy&#039;: 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.<br />1&gt;&#160; &#160; &#160; &#160; &#160; c:/program files/microsoft visual studio 10.0/vc/include/string.h(105) : 参见“strcpy”的声明<br />warning C4996: &#039;fopen&#039;: This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.<br />1&gt;&#160; &#160; &#160; &#160; &#160; c:/program files/microsoft visual studio 10.0/vc/include/stdio.h(234) : 参见“fopen”的声明<br />原因解释<br />这种微软的警告，主要因为那些C库的函数，很多函数内部是不进行参数检测的（包括越界类的），微软担心使用这些会造成内存异常，所以就改写了同样功能的函数，改写了的函数进行了参数的检测，使用这些新的函数会更安全和便捷。关于这些改写的函数你不用专门去记忆，因为编译器对于每个函数在给出警告时，都会告诉你相应的安全函数，查看警告信息就可以获知，在使用时也再查看一下MSDN详细了解。库函数改写例子：<br />mkdir改写为 _mkdir <br />fopen”改写为 fopen_s <br />stricmp改写为 stricmp_s<br />strcpy改写为strcpy_s</p><p>&#160; &#160; 解决方案：<br />1&gt; 根据下面的warning提示：参见“fopen”的声明<br />&#160; &#160; &#160; &#160; 消息:“This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.”<br />&#160; &#160; &#160; &#160; 所以可以将函数按warning提示的第二句，改为使用fopen_s函数即可：<br />&#160; &#160; &#160; &#160; 例如:FILE *pFile=fopen(&quot;1.txt&quot;, &quot;w&quot;);<br />&#160; &#160; &#160; &#160; &#160; &#160;改为：<br />&#160; &#160; &#160; &#160; &#160; &#160;FILE* pFile;<br />&#160; &#160; &#160; &#160; &#160; &#160;fopen_s(&amp;pFile, &quot;1.txt&quot;, &quot;w&quot;); <br />2&gt; 还是根据warning提示的地三句话:use _CRT_SECURE_NO_DEPRECATE<br />&#160; &#160; &#160; &#160; 项目|属性|配置属性|C/C++|命令行|附加选项,加入【/D &quot;_CRT_SECURE_NO_DEPRECATE&quot; 】(注：加入中括号中完整的内容)<br />3&gt; 降低警告级别：项目|属性|配置属性|C/C++|常规,自己根据情况降低警告级别（此法不推荐）<br />&#160; &#160; 注意：高度重视警告：使用编译器的最高警告级别。应该要求构建是干净利落的（没有警告）。理解所有警告。通过 修改代码而不是降低警告级别来排除警告。<br />&#160; &#160; 编译器是你的朋友。如果它对某个构造发出警告，这经常是说明你的代码中存在潜在的问题。成功的构建应该是无声无息的（没有警告的）。【《C++编程规 范》】</p><br /><p>通过修改配置，第2中方法可以用</p>]]></description>
			<author><![CDATA[dummy@example.com (xuyg)]]></author>
			<pubDate>Mon, 15 Jun 2015 10:08:32 +0000</pubDate>
			<guid>http://www.itecfun.com/viewtopic.php?pid=3318#p3318</guid>
		</item>
	</channel>
</rss>
