gpt4 book ai didi

c++ - 如何解决这个 winsock 错误?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:25:01 25 4
gpt4 key购买 nike

C:\Users\Chan\Desktop\test - fail\winsock2 socket server.cpp: In function `int _tmain()':
C:\Users\Chan\Desktop\test - fail\winsock2 socket server.cpp:48: error: `getaddrinfo' was not declared in this scope
C:\Users\Chan\Desktop\test - fail\winsock2 socket server.cpp:59: error: `freeaddrinfo' was not declared in this scope
C:\Users\Chan\Desktop\test - fail\winsock2 socket server.cpp:68: error: `freeaddrinfo' was not declared in this scope
C:\Users\Chan\Desktop\test - fail\winsock2 socket server.cpp:74: error: `freeaddrinfo' was not declared in this scope

使用这个头文件

#include "winsock2.h"
#include "windows.h"
#include "WS2tcpip.h"

最佳答案

头文件 WS2tcpip.h 使用这个定义:

#if (_WIN32_WINNT >= 0x0600)

这意味着在您的构建中,您应该将 _WIN32_WINNT 定义为 0x600 (Vista) 或更高。这意味着您需要的 API 在 WinXP 中不存在。

关于c++ - 如何解决这个 winsock 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20603898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com