通过遍历下列哈希表找到键对应值的代码void haxi stdunordered_mapstdstring Slice sliceMap; stdvectorSlice SALL; for int i = 0; i cluster_centroids-size; ++i Slice slices; SALLpush_backslices; Slice& slice0 = SALLi;
遍历哈希表并找到键对应值的代码如下:
for (auto it = sliceMap.begin(); it != sliceMap.end(); ++it) {
std::cout << "Key: " << it->first << std::endl;
std::cout << "Value: " << std::endl;
std::cout << " Index: " << it->second.index << std::endl;
std::cout << " Centroid: (" << it->second.centroid.x << ", " << it->second.centroid.y << ", " << it->second.centroid.z << ")" << std::endl;
}
这段代码使用迭代器遍历哈希表sliceMap,并输出每个键对应的值。
原文地址: https://www.cveoy.top/t/topic/h1JP 著作权归作者所有。请勿转载和采集!