贝贝花花包包店,精品555皮具,钱夹,皮夹

字体:  

如何将字符串转换为地址?

cl_mark 发表于: 2008-4-18 22:23 来源: ACE 开发者

怎样将字符串192.168.1.233:21转换为ace_inet_addr的对象?说详细点,谢谢拉

最新回复

earthdog at 2008-4-22 17:30:47
ACE_INET_Addr有一个构造函数满足你的要求:

/**
   * Initializes an ACE_INET_Addr from the <address>, which can be
   * "ip-number:port-number" (e.g., "tango.cs.wustl.edu:1234" or
   * "128.252.166.57:1234").  If there is no ':' in the <address> it
   * is assumed to be a port number, with the IP address being
   * INADDR_ANY.
   */
  explicit ACE_INET_Addr (const char address[],
                          int address_family = AF_UNSPEC);



调用方式就很简单了三,
ACE_INET_Addr addr("192.168.1.233:21", AF_INET);


同时,还有一个set()函数也可以做同样的操作:

  /**
   * Initializes an ACE_INET_Addr from the @a addr, which can be
   * "ip-number:port-number" (e.g., "tango.cs.wustl.edu:1234" or
   * "128.252.166.57:1234").  If there is no ':' in the <address> it
   * is assumed to be a port number, with the IP address being
   * INADDR_ANY.
   */
  int set (const char addr[], int address_family = AF_UNSPEC);

调用方式如下:
ACE_INET_Addr addr;
addr.set("192.168.1.233:21", AF_INET);

[ 本帖最后由 earthdog 于 2008-4-22 17:32 编辑 ]