我可以在多个平台上用 C++ 将字符串转换为 IP 地址吗 Windows(各种版本)和Unix系统?
最佳答案
您可以使用 inet_addr()
函数将表示为字符串的 IP 地址转换为可与其他套接字函数一起使用的形式。
这是一个使用示例(取自 here ):
int rc;
int s;
struct sockaddr_in myname;
/* clear the structure to be sure that the sin_zero field is clear */
memset(&myname, 0, sizeof(myname));
myname.sin_family = AF_INET;
myname.sin_addr = inet_addr("129.5.24.1");
/* specific interface */
myname.sin_port = htons(1024);
关于c++ 字符串到 ipAddress windows/unix 系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5377998/