Iterating over a map(c++)?
I have in my class a map:
map< string, string > phonesMap
of pairs of (username, phone number )
I want to output all the pairs into a file.
I have a method saveMap():
ofstream out( filename );
map< string, string >::const_iterator it;
for ( it = phonesMap.begin(); it != phonesMap.end(); it++ ) {
out << it->? << " " << it->?;
}
The question is how do I output the key and the value?
Another question similiar to this, is if have a value in a map how do I get the key from it?
|