winsock 弃用没有警告 [英] winsock deprecated no warnings

查看:46
本文介绍了winsock 弃用没有警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 VS2015(C++ 控制台应用程序)创建一个 UDP 多播套接字程序.

I am trying to create a UDP multicast socket program using VS2015 (C++ console application).

我收到以下错误,

Error   C4996   'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings mulitcast_listener

我尝试通过项目"->属性"->配置属性"->C/C++"->预处理器"->预处理器定义"将 _WINSOCK_DEPRECATED_NO_WARNINGS 符号添加到我的项目设置中.. 但还是一样.

I tried to add _WINSOCK_DEPRECATED_NO_WARNINGS symbol to my project settings via "Project"->"Properties"->"Configuration properties"->"C/C++"->"Preprocessor"->"Preprocessor definitions" .. But still it says the same.

然后我尝试在 #include "stdafx.h" 上方添加符号喜欢

And then I tried to add symbol above #include "stdafx.h" like

#define _WINSOCK_DEPRECATED_NO_WARNINGS 1

然后在项目"->属性"->配置属性"->C/C++"->常规->SDL检查上否(/sdl-)

and then No(/sdl-) on "Project"->"Properties"->"Configuration properties"->"C/C++"->General->SDL checks

现在我收到一条错误消息说

now I get a error message saying

Warning C4603   '_WINSOCK_DEPRECATED_NO_WARNINGS': macro is not defined or definition is different after precompiled header

最后我尝试实现

inet_pton(AF_INET, HELLO_GROUP, (PVOID *)(&mreq.imr_multiaddr.s_addr));

代替

mreq.imr_multiaddr.s_addr = inet_addr(HELLO_GROUP);

我需要了解为什么即使在添加 _WINSOCK... 宏后错误仍未解决.

I need to understand why the error didn't resolved even after adding the _WINSOCK... macro.

提前致谢.

推荐答案

如评论中所述,解决方案是确保行

As noted in the comments, the solution is to make sure that the line

#define _WINSOCK_DEPRECATED_NO_WARNINGS

放在

#include "stdafx.h"

但在其他 #include 语句之前.

but before the other #include statements.

这篇关于winsock 弃用没有警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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