同じ問題を再度投稿して申し訳ありませんが、提案された解決策を使用しましたが、部分的に機能しました...問題を明確にしたい:
それで:
次のように、マップのベクトルを定義しました。
typedef vector<map<string,unsigned int> > myvec;
そして、次のようなベクトルのマップ(私はそれをインデックスと呼びました):
typedef map<string,vector<unsigned int> > index;
それから私は次のことをしました:
myCoogleと呼ばれる私のクラスで、私は宣言しましたmyvec maps_vec;
そして私はそれを地図で埋めました...
各マップには、単語(文字列)と数字(未使用の整数)があります。
ここまでは順調ですね。
私も宣言しましたindex the_index;
次に、すべての異なる単語をthe_vecからthe_indexにコピーします。
言葉は文字列になります...
そして、各ベクトルについて、マップのベクトルに格納されている数値を追加します。
例えば:
the_vecには3つのマップがあります。
1つ目は:チキン、1 | 人、1 | エレベーター、5 | is、2 | ..。
2番目は:person、2 | アイスクリーム、3 | is、3 | ..。
3番目は:エレベーター、1 | クマ、1 | is、4 | チキン、3 | ..。
したがって、the_indexは次のようになります。
単語、[intのベクトル]
チキン[1,0,3]
人、[1,2,0]
エレベーター[5,0,1]
is [2,3,4]
アイスクリーム[0,3,0]
クマ[0,0,1]
OKこれが私の関数です:
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を印刷しようとしましたが、すべて問題ありませんでした。しかし、他のマップもスキャンした後に印刷しようとすると、これが発生します。
ただし、「正常にビルド」します。
そして、プログラムを実行すると、このウィンドウがポップアップします。
したがって、2番目の'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つのマップを印刷する場合のスクリーンショットです。