gpt4 book ai didi

c++ - 错误 C2065 : 'socklen_t' : undeclared identifier

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

整个错误是:

Error   1   error C2065: 'socklen_t' : undeclared identifier    c:\users\richard\documents\visual studio 2010\projects\server\server\server.cpp 41  1   Server

这是有问题的行:

int iRcvdBytes=recvfrom(iSockFd, buff, 1024000, 0, (struct sockaddr*)&cliAddr, (socklen_t*)&cliAddrLen);

我有这些 header :

#include <winsock2.h>
#include <windows.h>

#include <direct.h>
#include <stdlib.h>
#include <stdio.h>

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

我还在 Visual Studio 2010 中的链接器中添加了 WS2_32.lib。

还有什么可能导致这个问题?我只是想重写我的简单 UDP 程序以在 Windows 下工作。

最佳答案

socklen_t 类型在 Windows 的 WS2tcpip.h 中定义。这不是从 winsock2.h (AFAICT) 传递包含的。您需要手动包含 WS2tcpip.h 才能使用 socklen_t 类型。

关于c++ - 错误 C2065 : 'socklen_t' : undeclared identifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4453992/

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