【发布时间】:2011-09-25 22:12:57
【问题描述】:
在 C++ 中,我们使用网络上的套接字发送数据。我知道我们需要使用 htons() 、 ntohs() 函数来维护字节顺序 big endian 和 little endian。
支持我们有以下数据要发送
int roll;
int id;
char name[100];
这也可以包装到结构中。
我的困惑是,对于 roll 和 id,我们可以使用 htons() 函数。但是对于字符串name,我们应该怎么做呢?我们需要使用任何这样的功能吗?它可以在 mac、intel 和其他网络等每台机器上运行吗?
我想在一个数据包中发送所有三个字段。
【问题讨论】:
标签: c++ sockets endianness