IDE无法识别Inet_pton
我正在尝试在C ++中编写一个简单的TCP客户端。我正在关注本指南这是我到目前为止的简短代码:
main.cpp
:
#include "messenger.h"
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#endif
#include <winsock2.h>
#pragma comment (lib, "Ws2_32.lib")
int main()
{
WSADATA d;
if (WSAStartup(MAKEWORD(2, 2), &d)) {
perror("Failed to initialize.\n");
}
Messenger::connect();
WSACleanup();
return 0;
}
`messenger.h':
class Messenger {
public:
static void connect();
...
}
and messenger.cpp
:
#include "messenger.h"
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <unistd.h>
#include <winsock2.h>
#include <wspiapi.h>
#include <Ws2tcpip.h>
#pragma comment(lib, "ws2_32.lib")
using namespace std::chrono_literals;
#define IP "192.168.0.99"
#define PORT 3030
SOCKET prop_socket = INVALID_SOCKET;
std::thread Messenger::receive_thread;
void Messenger::connect() {
setup();
receive_thread = std::thread{listen_for_messages};
}
void PropulsionMessenger::setup() {
std::string ipAddress = IP;
sockaddr_in hint;
ZeroMemory( &hint, sizeof(hint) );
hint.sin_family = AF_INET;
hint.sin_port = htons(PORT);
inet_pton(AF_INET, ipAddress.c_str(), &hint.sin_addr);
}
...
但是Clion突出显示inet_pton
告诉我,使用未宣布的标识符'inet_pton'
。我相信所有字段都充满了正确的数据类型,并且我拥有所有必需的标头文件。我没有其他错误。
I am trying to write a simple-ish TCP client in C++. I was following this guide and this is the short code I have so far:
main.cpp
:
#include "messenger.h"
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#endif
#include <winsock2.h>
#pragma comment (lib, "Ws2_32.lib")
int main()
{
WSADATA d;
if (WSAStartup(MAKEWORD(2, 2), &d)) {
perror("Failed to initialize.\n");
}
Messenger::connect();
WSACleanup();
return 0;
}
`messenger.h':
class Messenger {
public:
static void connect();
...
}
and messenger.cpp
:
#include "messenger.h"
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <unistd.h>
#include <winsock2.h>
#include <wspiapi.h>
#include <Ws2tcpip.h>
#pragma comment(lib, "ws2_32.lib")
using namespace std::chrono_literals;
#define IP "192.168.0.99"
#define PORT 3030
SOCKET prop_socket = INVALID_SOCKET;
std::thread Messenger::receive_thread;
void Messenger::connect() {
setup();
receive_thread = std::thread{listen_for_messages};
}
void PropulsionMessenger::setup() {
std::string ipAddress = IP;
sockaddr_in hint;
ZeroMemory( &hint, sizeof(hint) );
hint.sin_family = AF_INET;
hint.sin_port = htons(PORT);
inet_pton(AF_INET, ipAddress.c_str(), &hint.sin_addr);
}
...
However CLion highlights inet_pton
and tells me that Use of undeclared identifier 'inet_pton'
. I believe all of the fields are filled with the correct data types and I have all of the required header files. I get no other errors.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论