如题

解决方案 »

  1.   

    补充:
    命令行中的ipconfig也可以.
      

  2.   

    能不能说说gethostname怎么用??我手头没有MSDN
      

  3.   

    WSADATA wsaData;
    WSAStartup(MAKEWORD (2,2), &wsaData);char hostname[40] = {0,};
    gethostname( hostname, sizeof(hostname));
    struct hostent *phostent = gethostbyname(hostname);
    // host name
    m_strHostName.Format("%s", phostent->h_name );
    // host ip
    char* stringhostip = inet_ntoa( *(struct in_addr *) phostent->h_addr_list[0] );
    m_strHostIp.Format("%s", stringhostip);WSACleanup();
      

  4.   

    楼上兄弟的代码可以,不过用的时候要包含上头文件#include "Winsock2.h"和Ws2_32.lib
      

  5.   

    gethostname( hostname, sizeof(hostname));
      

  6.   

    #include "Winsock2.h"
    #include "Ws2_32.lib"包含了这两个文件会出下面的错误;为什么??急急
    fatal error C1083: Cannot open include file: 'Ws2_32.lib': No such file or directory
      

  7.   

    在project->setting中的link里包含,或者add to project->file
      

  8.   

    晕,我可没有说让你包含"Ws2_32.lib"啊,我的意思是让你连接Ws2_32.lib,我想你看到.lib就应该知道是连接库了啊,晕晕晕晕晕晕晕晕晕晕晕晕晕晕晕晕晕晕晕晕