c++ 字符串到 ipAddress windows/unix 系统

标签 c++ windows string unix ip-address

我可以在多个平台上用 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/

相关文章:

java删除列表中的反向字符串

c++ - 理解策略模式

windows - Windows XP 上的不可移动文件

c++ - 如何从 std::vector of real double 填充 std::vector of complex double

ios - Windows 命令行中的 iPhone 屏幕截图

c# - COM DLL 依赖项中静态 DLL 数据的多个进程和拷贝

c# - 字符串索引和子字符串 C#

string - 如何比较字符串和整数 Postgres

c++ - 如何区分空结构和一个字符?

c++ - 比较c++中同一 vector 的元素