void CDic::LoadDic(const string strFileName)
{
FILE *pf=fopen(strFileName.c_str(),"rb");
if(!pf)
{
AfxMessageBox("Unable to open file!");
return;
}
fseek(pf,0L,SEEK_END);
long lFileLen=ftell(pf);
rewind(pf);
char *Buffer=new char[lFileLen+1];
memset(Buffer,'\0',lFileLen+1);
fread(Buffer,lFileLen,1,pf);
char *ch_N,*ch_E,*ch_C;
ch_N=ch_E=Buffer;
int nRegister;
pair<string,string> pairPair; do{
while(*ch_E!=0x09) ch_E++;
*ch_E='\0';
nRegister=atoi(ch_N);
ch_E++;
ch_C=ch_E;
while(*ch_C!=0x09) ch_C++;
*ch_C='\0';
ch_C++;
ch_N=ch_C;
while(*ch_N!=0x0D) ch_N++;
*ch_N='\0';
pairPair.first=ch_E;
pairPair.second=ch_C;
m_mapWord.insert(make_pair(nRegister,pairPair));
ch_N+=2;
}while(*ch_N!='\0'); delete [] Buffer;
fclose(pf);
}
{
FILE *pf=fopen(strFileName.c_str(),"rb");
if(!pf)
{
AfxMessageBox("Unable to open file!");
return;
}
fseek(pf,0L,SEEK_END);
long lFileLen=ftell(pf);
rewind(pf);
char *Buffer=new char[lFileLen+1];
memset(Buffer,'\0',lFileLen+1);
fread(Buffer,lFileLen,1,pf);
char *ch_N,*ch_E,*ch_C;
ch_N=ch_E=Buffer;
int nRegister;
pair<string,string> pairPair; do{
while(*ch_E!=0x09) ch_E++;
*ch_E='\0';
nRegister=atoi(ch_N);
ch_E++;
ch_C=ch_E;
while(*ch_C!=0x09) ch_C++;
*ch_C='\0';
ch_C++;
ch_N=ch_C;
while(*ch_N!=0x0D) ch_N++;
*ch_N='\0';
pairPair.first=ch_E;
pairPair.second=ch_C;
m_mapWord.insert(make_pair(nRegister,pairPair));
ch_N+=2;
}while(*ch_N!='\0'); delete [] Buffer;
fclose(pf);
}
这个函数没见过诶。。
var
hf : THandle;
lFileLen : DWORD;
Buffer: PChar;
ch_N,ch_E,ch_C:PChar;
nRegister:Integer;
pair:TpairPair;//假设这个类已经存在,VC中的模版Delphi只能用类来实现begin//如果需要和C++通用, 可以使用PChar
hf := FileOpen(strFileName,fmOpenRead or fmShareDenyNone);
if (hf = INVALID_HANDLE_VALUE) then
begin
ShowMessage(Unable to open file!");
Exit;
end;
lFileLen = GetFileSize(hf,nil);
FileSeek(hf,0,FILE_BEGIN);//可以不使用这句,因为没有SEEK到末尾,只是为了和rewind对应
Buffer := GetMem(iFileLen+1);
Fill(Buffer^,#0,iFileLen+1);//两句话可以使用Buffer := AllocMem(iFileLen+1);替代
FileRead(hf,Buffer^,iFileLen);
ch_N := Buffer;
ch_E := Buffer;
repeat
while (ch_E^ <> #$09) do inc(ch_E);
ch_E^ := #0;//可能所有字符串使用#09隔开,碰到即以0结尾
nRegister := strtoint(strpas(ch_N)); //nRegister = atoi(ch_N);
//这句话我有点不解,对C知道不多,请自行参考之后酌情修改
inc(ch_E);
ch_C := ch_E;
while (ch_C^<>#$09) do inc(ch_C);
ch_C^ := #0;
inc(ch_C);
ch_N := ch_C;
while (ch_N^<>#$0D)do inc(ch_N);
ch_N^ := #0;
pairPair.first := ch_E;//整个数据的第2部分
pairPair.second := ch_C;//整个数据的第3部分
m_mapWord.insert(make_pair(nRegister,pairParr));//这句请酌情修改
//如果原来中没有这个类请自行构造, 可以用TList处理
inc(ch_N,2);
until (ch_N^ = #0);
FreeMem(Buffer,iFileLen);
FileClose(hf);//CloseHandle(hf);
end;
//整个过程就是从文件中读取数据,并存入表中,应该是方便以后使用
//文件内容格式:
1234567#09Hello#09Hello2#$0D#$0A
每行如此,第一个是单词的序号,用ascii表示
第二个应该是单词,第三个应该注释吧
#09为内容间隔符,#0D#0A回车换行符。我鄙视扑火飞蛾,delphi怎么了?delphi着你惹你了??
multimap<int,pair<string,string> >::reverse_iterator iter_map;
multimap<int,pair<string,string> > m_mapWord;
帮忙,送分啊。
multimap<int,pair<string,string> >::reverse_iterator iter_map;
multimap<int,pair<string,string> > m_mapWord;演示的文件内容:
0 what 什么
0 is 是(第三人称)
0 what's what is
0 your 你的;你们的
0 name 名字
0 my 我的
0 I 我