1
爲std::unordered_map
,您是否可以訪問某些存儲桶中的元素i
如果其bucket_size
不爲零?std :: unordered_map,你可以用桶號訪問桶中的元素嗎?
爲std::unordered_map
,您是否可以訪問某些存儲桶中的元素i
如果其bucket_size
不爲零?std :: unordered_map,你可以用桶號訪問桶中的元素嗎?
的答案是使用std::unordered_map::begin(bucket_num)
或std::unordered_map::cbegin(bucket_num)
獲得指向第一個元素到桶迭代器和迭代的剷鬥末端 std::unordered_map::end(bucket_num)
for (auto it = u_map.begin(bucket_num); it!= u_map.end(bucket_num); ++it)
{
cout<<it->first<<", "<<it->second<<endl;
}
看看這裏:HTTP:// EN。 cppreference.com/w/cpp/container/unordered_map並向下滾動到「Bucket Interface」部分。 – paddy
謝謝!完全錯過了。 – Allanqunzi