std::map<std::string, std::string> myMap;
std::map<std::string, std::string>::iterator i = m_myMap.find(some_key_string);
if(i == m_imagesMap.end())
return NULL;
string *p = &i->first;
最后一行有效吗? 我想把这个指针p存到别的地方,它在整个程序的生命周期内都有效吗? 但如果我向该映射添加更多元素(使用其他唯一键)或删除其他键,那么它不会重新分配此字符串(键-值对),因此p会变得无效吗?
typedef const std::string string;
而不是using namespace std;
,否则它无法编译,这很令人困惑... - pqnet