あなたのコードにはたくさんの問題があります。最も些細なこと: マップの宣言の後にセミコロンがありません。また、最後に余分なブレースがあります。
最後に、マップのキーは値であり、コンテナーconst
を呼び出すと、取得されるのはではなくです。プログラムを修正する方法は次のとおりです。begin()
const
const_iterator
iterator
#include <map>
#include <set>
#include <iostream>
using std::map;
using std::set;
using std::cout;
using std::endl;
int main()
{
map< map< set< int > ,int >, int> mymap[2];
// ^ MISSING SEMICOLON HERE
map< map< set< int > ,int >, int> :: iterator it1;
map< set< int > ,int > ::const_iterator it2;
// ^^^^^^^^^^^^^^ <== MAP KEYS ARE CONST VALUES!
set < int > ::const_iterator it3;
// ^^^^^^^^^^^^^^ <== MAP KEYS ARE CONST VALUES!
for(it1=mymap[0].begin();it1!=mymap[0].end();it1++)
{
for(it2=(it1->first).begin();it2!=(it1->first).end();it2++)
{
for(it3=(it2->first).begin();it3!=(it2->first).end();it3++)
{
std::cout<<*it3<<" "<<it1->second<<endl;
}
}
}
// } <== EXTRA BRACE HERE
}
また、C++11 では、 を使用して物事を単純化できることに注意してauto
ください。これにより、この種の問題を回避できます。
int main()
{
map< map< set< int > ,int >, int> mymap[2];
for (auto it1 = mymap[0].begin(); it1 != mymap[0].end(); it1++)
// ^^^^
{
for (auto it2 = (it1->first).begin(); it2 != (it1->first).end(); it2++)
// ^^^^
{
for (auto it3=(it2->first).begin(); it3!=(it2->first).end(); it3++)
// ^^^^
{
std::cout<<*it3<<" "<<it1->second<<endl;
}
}
}
}
範囲ベースのfor
ループを使用すると、これがさらに簡単になります。
int main()
{
map< map< set< int >, int >, int> mymap[2];
for (auto const& m : mymap[0])
{
for (auto const& s : m.first)
{
for (auto const& e : s.first)
{
std::cout << e << " " << m.second << endl;
}
}
}
}