ここで何が起こっているのか、どこが間違っているのですか?
vector<int> a(5);
for(int i=0; i<5; i++) cin>>a[i]; //Input is 1 2 3 4 5
for(int i=0; i<5; i++) cout<<a[i]<<" "; //Prints correct, 1 2 3 4 5
cout<<endl;
for(VI::iterator it = a.begin(); it!=a.end(); ++it) {
cout<<a[*it]<<" "; //Prints incorrect output
}
cout<<endl;
間違った出力の最後の要素がa[*(a.end()-1)]
あり、最初の要素が実際にあるべきものから欠落しているようです。