我正在使用 multimap 来存储值。我只想在插入 multimap 时检查值是成功还是失败。
我正在尝试使用以下代码
if (MultiMap.insert(TypeDefMap::value_type(Id, ans)))
return 1;
else
return 0;
但这给出了标量类型预期的错误。
我想我在这里遗漏了一些愚蠢的东西。我尝试将类型转换为 int 和 bool 但没有成功。
有什么建议吗?
最佳答案
根据文档(multimap insert
方法)
In the versions returning a value, this is an iterator pointing to the newly inserted element in the multimap.
您应该检查迭代器 != end() 是否表示成功,否则表示失败。
关于C++ Multimap 插入函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6043500/