【发布时间】:2017-07-11 06:19:17
【问题描述】:
在将键、值对插入映射时,如果键为“”并且对应的值存在,将是什么行为。例如
std::map<std::string, std::string> map1;
std::string key = "";
std::string value = "xyz";
map1.insert(std::pair<std::string, std::string>(key, value));
处理这种情况的最佳方法是什么?
【问题讨论】:
-
您是在问
map::insert是否对空字符串有特殊行为? -
juanchopanza 有什么特殊行为吗?这种情况有效吗?我怎样才能避免这种特殊情况?
-
不,没有任何特殊行为,但您的问题暗示它是,或者您还没有阅读
map::insert的任何文档。 -
或者你认为
std::string有一个特殊的状态,“null”。这也不是真的。你所拥有的只是一个空字符串。这会是混乱的根源吗? -
啊……非常感谢。纠正自己
标签: c++ templates dictionary stl