VS中一些warning的消除

来源:互联网 发布:html简单小游戏源码 编辑:程序博客网 时间:2024/06/01 12:33

1、warning C4018: “<”: 有符号/无符号不匹配
出错代码:
for(int i = 0; i < AllShapes.size(); i++)
出错原因:AllShapes是一个vector容器, AllShapes.size() 在容器说明中被定义为: unsigned int 类型, 而j是int 类型 所以会出现: 有符号/无符号不匹配警告
错误改正 : 定义j为unsigned 类型后就可以了
即:for(unsigned int i = 0; i < AllShapes.size(); i++)

程序中还有几个类似的warning,也以同样的方法改掉

2、warning C4996: 'mkdir': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _mkdir. See online help for details.
出错代码:mkdir("result");
出错原因,这种声明方式不被造成,应加上_
错误改正:_mkdir("result")

3. warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for detail
错误改正:方法一  sprintf->sprintf_s

方法二 更改预处理定义:项目 ->属性 ->配置属性-> c/c++ -> 预处理器 -> 点击预处理器定义->编辑,加入_CRT_SECURE_NO_WARNINGS,即可。

1 0
原创粉丝点击