[英]C++: no match for operator< when trying to iterate through boost::unordered_map<string,int>
[英]Iterate over map<boost::tuple<int, string>, int> in C++
我有以下內容:
map<boost::tuple<int, string>, int> edges;
edges[boost::make_tuple(1, "a")] = 1;
一個簡單的cout << edges[boost::make_tuple(1, "a")] << endl;
確認它為1;
我該如何迭代呢? 以下似乎無效:
typedef map<boost::tuple<int, string>, int>::iterator it_type;
for(it_type i = edges.begin(); i != edges.end(); i++) {
cout << i->first << endl;
}
謝謝!
i->first
是一個tuple
。 因此,您不能只是將其cout
。
請參閱訪問boost ::元組的成員以了解如何訪問元組。
您可以使用i->second
因為它是一個int
,因此可以使用cout
來使用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.