首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

windows上vs2010显示本机ip无法通过,源码如上,请求指教,多谢

2013-01-07 
windows下vs2010显示本机ip无法通过,源码如下,请求指教,谢谢#include StdAfx.h #includeafx.h#include

windows下vs2010显示本机ip无法通过,源码如下,请求指教,谢谢
#include "StdAfx.h" 
#include<afx.h>
#include<winsock2.h>
#pragma comment(lib, "ws2_32.lib")
int main(int argc,char**argv)
{
   
   struct hostent*hn;
   CString strIPAddr;
   char HostName[32];
   if(gethostname(HostName,sizeof(HostName))==0)
   {
   if( hn=gethostbyname(HostName))
   {
   strIPAddr=inet_ntoa(*(struct in_addr*)hn->h_addr_list[0]);
       cout<<strIPAddr<<endl
   }
 
   }  
   return 0;
}
[解决办法]

引用:
可能需要先WSAStartup

++
struct hostent*hn=new hostent;

热点排行