#include<utility>
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#define M 100000
using namespace std;
int main() {
map<char, vector<pair<char,int> > > graph;
vector<pair<char,int> > vector1;
vector1.push_back(pair<char,int>('B',4));
graph['A'] = vector1;
map<char,int> citydistances;
citydistances['A'] = 0;
vector<pair<char,int> >::iterator edge;
for (map<char,int>::iterator i=citydistances.begin(); i!=citydistances.end(); ++i) {
vector<pair<char, int> > cities = graph[i->first];
for (vector<pair<char,int> >::iterator j=cities.begin(); j!=cities.end(); ++j) {
if (citydistances.find(j->first)==citydistances.end()) {
edge = j;
//point 1
cout<<edge->first<<endl;
}
}
}
//point 2
cout<<edge->first<<endl;
return 0;
}
我试图尽可能缩短我的代码,以专注于行为出乎意料的部分。我不明白为什么第edge->first
1 点和第 2 点的值不同。edge->first
在第 1 点是“B”,但'\000'
在第 2 点。有人可以帮帮我吗?