求助:error C2653: 'General' : is not a class or namespace name
kyzww 2010-08-11 11:08:47 #include "afx.h"
#include <stdlib.h>
#include <iostream>
#include <winsock2.h>
#include <windows.h>
#include <math.h>
using namespace std;
CString General::GetIp()
{
CString ipStr="";
char szTempFile [MAX_PATH];
char szTempPath [MAX_PATH];
GetTempPath(MAX_PATH, szTempPath);
UINT nResult=GetTempFileName (szTempPath, _T ("ip"),0,szTempFile);
int ret=URLDownloadToFile(NULL,"http://www.ip138.com/ip2city.asp",szTempFile,0,NULL);
if (ret==S_OK) //如果下载成功
{
FILE *f;
f=fopen(szTempFile,"rb");
if(f)
{
fseek(f,0,SEEK_END);//得到文件大小
int ilength=ftell(f);
fseek(f,0,SEEK_SET);
if(ilength>0)
{
char szMyIp[16] = {0};
char fBuffer[256] = {0};
fread(fBuffer, 256, 1, f);
int iBegin,iEnd;
for (int i = 0; i < ilength; i++)
{
//取得"["的位置
if (fBuffer[i] == 0x5b)
iBegin = i;
//取得"]"的位置
if (fBuffer[i] == 0x5d)
{
iEnd = i;
break;
}
}
memcpy(szMyIp, fBuffer + iBegin + 1, iEnd - iBegin - 1);
//AfxMessageBox(szMyIp);
ipStr=szMyIp;
}
}
}
}
int main()
{
GetIp();
return 0;
}
执行结果:
D:\新建文件夹 (2)\Text1.cpp(15) : error C2653: 'General' : is not a class or namespace name