When containers such as map are used to convert the iterator into a string object, an error is returned:
Error c2440: 'initializing': cannot convert from 'const class STD: basic_string <char, struct STD: char_traits <char>, class STD :: allocator <char> 'to' class STD: basic_string <char, struct STD: char_traits <char>, class STD: Allocator <char>
> &'
As you can see, in a map container similar to the following definition
Map <string, int> mapstringkey;
The key (string) is internally converted to const string for storage.
String & strkey = itr-> first;
An error is reported,
The Correct assignment method is as follows:
1, string strkey = itr-> first;
2, const string & strkey = itr-> first;
========================================================== ========
We can see from the following article that the key type defined by map is of the const type.
template < class Key, class T, class Compare = less<Key>, class Allocator = allocator<pair<const Key,T> > > class map;
Http://www.cplusplus.com/reference/stl/map/