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)或更高版本。这意味着WinXP中不存在所需的API。
关于c++ - 如何解决此winsock错误?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20603898/