【发布时间】:2021-11-27 08:36:43
【问题描述】:
我想使用向量对容器中的第一个值来获取该对的第二个值。如何在向量对中查找和遍历,并使用第一个值对获取第二对值的值?
在代码中,“G.keys()”是一个向量对,第一个值是字符,下一个是字符串。
void search_shortest_path(){
Graph<T> G = create_graph();
T source;
T destination;
std::cout<<"AVAILABLE ROUTES\n";
for(auto k: G.keys()){
std::cout<<k.first<<". "<<k.second<<"\n";
}
std::cout<<"Enter your starting point: ";
std::cin>>source;
std::cout<<"Enter your destination point: ";
std::cin>>destination;
//GET SECOND PAIR VALUE USING SOURCE AND DESTINATION ?
G.dijkstra_algorithm(source, destination);
}
【问题讨论】:
-
不清楚,你的代码不完整(你提到了一个字符和一个字符串,但我看到了
T)?请发帖minimal reproducible example。 -
你能用
std::find或std::find_if吗?
标签: c++ algorithm data-structures