#include   <iostream>  
#include   <windows.h>  
#include   <winsock2.h>  using namespace std;  int main(int argc, char *argv[])  
{char name[20]; 
 char* host_namename1; 
 int hostname; 
struct  hostent *pp=NULL;  
WSADATA   wsaData;    
WORD   wVersionRequested;  
   
  wVersionRequested   =   MAKEWORD(   2,   2   );    
hostname=gethostname(name,20); 
pp=gethostbyname(host_name);     printf("%d\n",hostname);  
 cout < <pp->h_name < <endl; 
    system("PAUSE");  
    return EXIT_SUCCESS;  

dev c++ bi编译通过,但运行不了,望高手执教 

解决方案 »

  1.   

    #include    <iostream>   
    #include    <windows.h>   
    #include    <winsock2.h>   
    #pragma comment(lib,"ws2_32")using namespace std;   int main(int argc, char *argv[])   
    {
      char name[20];
      WSADATA wsa;
      WSAStartup(MAKEWORD(2,2),&wsa);
      gethostname(name,20);    
      cout  <<name <<endl;  
      system("PAUSE");   
      return EXIT_SUCCESS;   
    }  
      

  2.   

    #include    <iostream> 
    #include    <stdio.h>  
    #include    <windows.h>   
    #include    <winsock2.h>   using namespace std;   int main(int argc, char *argv[])   
    {char name[20];  
     char* host_namename1;  
     int hostname;  
    struct  hostent *pp=NULL;   
    WSADATA   wsaData;     
    WORD   wVersionRequested;      
    WSAStartup(MAKEWORD(2,2),&wsa);      
    hostname=gethostname(name,20); 
    if(hostname==0)

    pp=gethostbyname(host_name);  
        printf("%s\n",name);   
     cout  <  <pp->h_name  <  <endl;  
        system("PAUSE"); 
    return EXIT_SUCCESS;
    }  
    WSAClearup();       
    }  
      

  3.   

    wVersionRequested   =   MAKEWORD(   2,   2   ); 
      改成
    WSAStartup(MAKEWORD(2,2),&wsa);