簡體   English   中英

遍歷地圖 <boost::tuple<int, string> ,int&gt;在C ++中

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM