#include   <winsock2.h>   
  #include   <iostream.h>   
    
  int   main()   
  {   
  char     hostname[100]   ;   
  struct   hostent     *phostinfo   ;   
  WORD   wVersionRequested;   
  WSADATA   wsaData;   
  int   err;   
      
  wVersionRequested   =   MAKEWORD(   2,   2   );   
      
  err   =   WSAStartup(   wVersionRequested,   &wsaData   );   
  if   (   err   !=   0   )   
  {                                   
  cout   <<   "   winsock   start   up   error   !"   ;   
  return;   
  }     
  gethostname(hostname,strlen(hostname));   
  phostinfo   =   gethostbyname(hostname);   
    
  cout   <<   inet_ntoa(   *(in_addr   *)   phostinfo->h_addr     )   ;   
    
    
  }   
    
这段代码用于显示IP地址,但在连接时候会报错,希望各位大侠赐教,不甚感谢