这是一个显示本机ip的程序,调试出错的提示信息显示为
Compiling...
CheckIP.cpp
D:\程序设计\CheckIP\CheckIP.cpp(16) : error C2065: 'CString' : undeclared identifier
D:\程序设计\CheckIP\CheckIP.cpp(16) : error C2146: syntax error : missing ';' before identifier 'ip'
D:\程序设计\CheckIP\CheckIP.cpp(16) : error C2065: 'ip' : undeclared identifier
D:\程序设计\CheckIP\CheckIP.cpp(36) : error C2065: 'CheckIp' : undeclared identifier
Error executing cl.exe.
CheckIP.obj - 4 error(s), 0 warning(s)
-------------------------------------------------------------------------------------------------------------------------------------
源程序
#include "StdAfx.h"
#include "windows.h"
#include "winsock.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
void CheckIP()
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
CString ip;
PHOSTENT hostinfo;
wVersionRequested=MAKEWORD(2,0);
if(WSAStartup(wVersionRequested,&wsaData)==0)
{
if(gethostname(name,sizeof(name))==0)
{
if((hostinfo=gethostbyname(name))!=NULL)
{
LPCSTR ip=inet_ntoa(*(struct in_addr*)*hostinfo->h_addr_list);
printf("%s\n",ip);
}
}
WSACleanup();
}
}
int main(int argc, char* argv[])
{
CheckIp();
return 0;
}