반복기가 첫 번째 항목에서 시작하지 않는 몇 가지 이유 때문에지도를 반복하려고합니다.C++ map iterator가 첫 번째 항목에서 시작하지 않습니다.
const Noeud* origine = &noeuds.at(nomorigine);
map<string, Noeud>::iterator it;
origine->seeRoutes(); //Prints n5: n4 n6
it = origine->getRoutes().begin();
cout<<it->first<<endl; //Prints n4.
for(it = origine->getRoutes().begin(); it != origine->getRoutes().end(); it++){
cout<<it->first<<endl; //Prints n6.
}
void Noeud::seeRoutes() const{
cout<<getNom()<<": ";
for(auto it = routes.begin(); it != routes.end(); it++){
cout<<it->first<<" ";
}
cout<<endl;
}
나는 auto
을 사용해 보았지만 그 결과는 같습니다. 이 문제의 원인은 무엇일까요? 값을 기준으로
class Noeud{
public:
string getNom() const;
void setNom(const string& nom);
void ajouterRoute(const string& nomRoute, const Noeud noeud);
map<string, Noeud> getRoutes() const;
void seeRoutes() const;
private:
string nom;
map<string, Noeud> routes;
};
for 루프에서 ++을 사용하지 않는 이유는 무엇입니까? – Davar
와 비슷한 오류와 답변을 [https://stackoverflow.com/questions/30041907/can-i-use-nested-loops-with-vectors-in-cpp]. – PaulMcKenzie
@Davar 나는 ++와 it ++ 사이에 아무런 차이가 없다고 생각했다. for 루프에서 pre-increment하는 것이 항상 좋은가요? –