VS2008 fatal error C1083
打算写个在window下获取ip的小函数
使用的VS2008
代码如下 fatal error C1083: 无法打开包括文件:“Winsock2.h”: No such file or directory
对VS使用不熟 不知道怎么解
//#include "stdafx.h"
#include <Winsock2.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#pragma comment (lib,"ws2_32.lib")
int _tmain(int argc, _TCHAR* argv[])
{
char localip[8][32];
char caHostName[20];
char caTty[10];
int namelen=16;
char *tmp;
struct hostent *h;
struct in_addr addr;
memset(caHostName,0,sizeof(caHostName));
memset(caTty,0,sizeof(caTty));
gethostname(caHostName, namelen);
if ((h=gethostbyname(caHostName)) == NULL)
{
return 0;
}
int k=0;
while (h->h_addr_list[k] != NULL)
{
memcpy(&addr, h->h_addr_list[k], sizeof(struct in_addr));
tmp=inet_ntoa(addr);
strcpy(localip[k++],tmp);
cout<<localip[k-1]<<endl;
}
return 0;
}
<此程序为copy. just for test>