Technical Discussion :: C++
Home > Technical Interview Q&A > C++ > Discussion
10 / 187
How is an iteration over a map is carried out?
Answer:
Iteration over a map is simply iteration over a sequence of pair < const key, mapped_type >. For e.g. We might print out the entries of a phone book like this
Void f(map
Typedef map(string, number)::const_iteration CI;
For(CI =phone_book.begin( ); p!=phone_book.end( );++p)
cout<
}
A map iterator presents the elements in ascending order of its keys.
Asked In ::
Nathu
23 Feb, 2019 5:07 AM
Iteration over a map is simply iteration over a sequence of pair < const key, mapped_type >. For e.g. We might print out the entries of a phone book like this
Void f(map& phone_book) {
Typedef map(string, number)::const_iteration CI;
For(CI =phone_book.begin( ); p!=phone_book.end( );++p)
cout<first<<’\t’<second<<’\n’;
}
A map iterator presents the elements in ascending order of its keys.
Void f(map
Typedef map(string, number)::const_iteration CI;
For(CI =phone_book.begin( ); p!=phone_book.end( );++p)
cout<
}
A map iterator presents the elements in ascending order of its keys.