有一段文本,存放在 CString 类 strText 里,文本的类似这样:Air and Space Exhibit Plays Off Real Missions
Washington Post - 25 minutes agoThey found life on Mars yesterday. But the fact that the "life" was some ultraviolet paint daubed on a styrofoam rock at the National Air and Space Museum explains why this story isn't on the front page. 
从前有座山,山里有座庙!
NASA: Reality Surpasses Fantasy CBS News
On Mars and elsewhere, NASA science shines Florida Today(文本里有断行,有中文字符)需要得到
1、一个字符词典 strDictionary, 词典里存放上面文本中出现过的字符,按文本中出现的顺序排列,重复的字符被过滤掉,例如:
Air andSpceExhbtPlysOffRM2、需要一个函数快速检索文本 strText 中出现的每个字符在字典 strDictionary 中的位置索引怎么做最简洁?

解决方案 »

  1.   

    只有一个个取出来查找了。字符串有Find函数可以找到它出现的第一个位置索引。
      

  2.   

    我见过一个类似的东西,在《数据结构C++语言描述》-清华大学出版,第11章树中的11.7 实例研究:索引(Concordance)中,也话对你有用。
      

  3.   

    《C++ Primer》中的例子,使用STL
      

  4.   

    CMapString或者map最好了举一个例子
    {
    CMapStringToPtr StrMap;
    int *p=new int;
    *p=10;
    StrMap.SetAt("bluebohe",p);
    p=new int;
    *p=11;
    StrMap.SetAt("vcforever",p);
    p=NULL;
    POSITION pos=StrMap.GetStartPosition();
    while(pos)
    {
    CString str;
    StrMap.GetNextAssoc(pos,str,(void *&)p);
    if(p!=NULL)
    {
    delete p;
    p=NULL;
    }
    }
    StrMap.RemoveAll();

    }
    ——————————————————————————————#pragma warning(disable:4786)
    #pragma warning(disable:4251)
    #pragma warning(disable:4273)#include <map>
    using namespace std;struct ltstr
    {
    bool operator()(const char* s1, const char* s2) const
    {
    return strcmp(s1, s2) < 0;
    }
    }; {

    map<const char*, int, ltstr> months;
    months["january"] = 31;
    months["february"] = 28;
    months["march"] = 31;
    months["april"] = 30;
    months["may"] = 31;
    months["june"] = 30;
    months["july"] = 31;
    months["august"] = 31;
    months["september"] = 30;
    months["october"] = 31;
    months["november"] = 30;
    months["december"] = 31;
    map<const char*, int, ltstr>::size_type st = months.size();
    int i=months["january"];
    i=months["february"];
    months.clear();
    }