很抱歉再次发布同样的问题,但我使用了建议的解决方案,并且它部分工作......所以我想澄清这个问题:
所以:
我定义了一个地图向量,如下所示:
typedef vector<map<string,unsigned int> > myvec;
和这样的向量图(我称之为索引):
typedef map<string,vector<unsigned int> > index;
然后我做了以下事情:
在我的班级 myCoogle 中,我宣布myvec maps_vec;
我用地图填满了它...
在每张地图中都有一个单词(字符串)和一个数字(unsinged int)。
到目前为止,一切都很好。
我也声明了index the_index;
现在我想将所有不同的单词从 the_vec 复制到 the_index。
单词将是字符串...
对于每个向量,我将添加存储在地图向量中的数字。
例如:
the_vec 有 3 张地图。
第一个有:鸡,1 | 人,1 | 电梯,5 | 是,2 | ...
第二个有:人,2 | 冰淇淋,3 | 是,3 | ...
第三个有:电梯,1 | 熊,1 | 是,4 | 鸡,3 | ...
所以 the_index 应该是这样的:
word,[整数向量]
鸡[1,0,3]
人,[1,2,0]
电梯[5,0,1]
是[2,3,4]
冰淇淋[0,3,0]
熊[0,0,1]
好的,这是我的功能:
void Coogle::make_index()
{
    //SCAN THE FIRST MAP
    myvec::iterator myvec_iter;
    map<string,unsigned int>::iterator map_iter;
    index::iterator idx_iter = the_index.begin();
    for(map_iter=maps_vec[0].begin(); map_iter!=maps_vec[0].end(); ++map_iter)
    {
        the_index[map_iter->first].push_back(map_iter->second);
    }
    //SCAN THE OTHER MAPS
    myvec_iter=maps_vec.begin();
    myvec_iter++;
    int i=0; //FILE #
    while(myvec_iter!=maps_vec.end())
    {
        i++;
        for(map_iter=maps_vec[i].begin(); map_iter!=maps_vec[i].end(); ++map_iter)
        {
            string word=map_iter->first;
            cout << "DEALING WITH WORD \"" << word << "\"" << endl;
            index::iterator location;
            location=the_index.find(word);
            if(location!=the_index.end()) //if word found in the index
            {
                cout << "WORD EXISTS!" << endl;
                location->second[i]=map_iter->second;
            }
            else //if not found
            {
                cout << "WORD DOES NOT EXIST! NEW WORD." << endl;
                the_index[word].push_back(map_iter->second);
            }
        }
        cout << endl;
        ++myvec_iter;
    }
}
澄清: FILE# 是地图编号...我正在处理文件(* .txt 文件)。
好吧,在我扫描了第一张地图后,我尝试打印 the_index,一切都很好。但是我在扫描其他地图后尝试打印时得到了这个:

不过,“构建成功”。
当我运行程序时会弹出这个窗口。
所以我相信我的第二个“for”循环有问题。
任何人都可以帮忙吗?
非常抱歉,很长的帖子......
非常感谢 !!!
编辑:如果我不尝试打印 the_index,程序编译并运行得很好。但这当然还不够。但是我的打印功能还可以……这里:
void Coogle::print_index() const
{
    index::const_iterator iter;
    for(iter=the_index.begin();iter!=the_index.end();++iter)
    {
        cout << "Word: " << iter->first << endl;
        //cout << "Files number is: " << files_number << endl; //prints: 3
        for(int i=0; i<files_number;i++)
            cout << "file #" << i+1 << ": " << iter->second[i] << " , " << endl;
    }
}
编辑:
这是仅打印 1 张地图与打印 3 张地图的屏幕截图:
