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);
}
解决方案 »
- access查询按年月统计
- dll中的资源文件如何加密
- incompatible types:'string' and 'boolean'
- 如何将ListView中的内容导出到Excel表格里阿;再将Excel表格里的内容导到ListView里阿;
- 如何让quickrep.preview支持鼠标滚轮?
- 我想要在界面设计上加深一下自己的能力...谁能给我点建议呢~!!!
- 问两个关于存储过程的问题
- 如何输出固定宽度的字符串,类似使用 /t 的功能
- 怎么样使运行的程序最小话后在系统托盘区,就是和输入法在一起的系统托盘区
- 用ADO数据集读出的SQLSERVER记录为什么都有空格?而用BDE则不会。不想要咋办?
- 初学的我清醒的发现其实写程序并不难
- ★★★我15岁堂弟学delphi10天左右的作品
就能OKhttp://lysoft.7u7.net
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 我
{
FILE *pf=fopen(strFileName.c_str(),"rb"); // 以二进制,读的形式打开文件
if(!pf) // 打开失败
{
AfxMessageBox("Unable to open file!");
return;
}
fseek(pf,0L,SEEK_END); // 将指针移动到最后
long lFileLen=ftell(pf); // 获得当前文件指针的位置 返回当前位置与开始位置之间的BYTE数 这里即返回整个文件的长度
rewind(pf); // 将文件移动到最开始
char *Buffer=new char[lFileLen+1]; // 分配内存 以存放从文件读取的冬冬
memset(Buffer,'\0',lFileLen+1); // 初始化刚分配的内存位NULL
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++; // 如果读到的不是TAB键 ch_E下移
*ch_E='\0'; // 如果是TAB键 则将此TAB替换为 NULL终结符
nRegister=atoi(ch_N); // 将 ch_N的内容 转换为整型数据
ch_E++; // ch_E下移
ch_C=ch_E; // 将ch_C指向第一个TAB处 <本次循环中>
while(*ch_C!=0x09)
ch_C++; // 如果读到的不是TAB键 ch_C下移
*ch_C='\0'; // 如果是TAB键 则将此TAB替换为 NULL终结符
ch_C++; // ch_C下移
ch_N=ch_C; // 将ch_C指向第二个TAB处 <本次循环中>
while(*ch_N!=0x0D)
ch_N++; // 如果读到的不是TAB键 ch_N下移
*ch_N='\0'; // 如果是TAB键 则将此TAB替换为 NULL终结符 <本次循环中>第三个TAB键
pairPair.first=ch_E; // ch_E指向第一个 终结符处<第一个TAB处>
pairPair.second=ch_C; // ch_C指向第二个 终结符处<第二个TAB处>
m_mapWord.insert(make_pair(nRegister,pairPair)); // 插入到一个map,其中的标识符为nRegister这是唯一的
ch_N+=2; // 下移2BYTE
}while(*ch_N!='\0'); // 继续循环 直到遇到 NULL终结符 delete [] Buffer;
fclose(pf); // 关闭文件流
}