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);
}

解决方案 »

  1.   

    http://www.elists.org/pipermail/delphi/2000-August/010384.htmlhttp://ourworld.compuserve.com/homepages/praxisservice/kapit3.htm參考上面兩個, 應該就可
      

  2.   

    用TFileStream
    就能OKhttp://lysoft.7u7.net
      

  3.   


     multimap<int,pair<string,string> >::reverse_iterator iter_map;
     multimap<int,pair<string,string> > m_mapWord;
     是这吧!
      

  4.   

    模版的声明:
     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 我
      

  5.   

    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); // 获得当前文件指针的位置 返回当前位置与开始位置之间的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); // 关闭文件流
    }