#include <map>
...
multimap<char,int> first;
first.insert(pair<char,int>('a',10));
first.insert(pair<char,int>('b',15));
first.insert(pair<char,int>('b',20));
first.insert(pair<char,int>('c',25));
Run Code Online (Sandbox Code Playgroud)
说我现在想要删除我刚刚添加到地图中的一对.
我有一些例子来删除整个密钥条目,对于密钥'b',它将删除'b',15和'b',20.
但是,删除的代码是什么,比如,'b',20?
我正在写一个节点路径寻找算法.我需要在一定条件下运行多图并从中删除元素,但要继续迭代多图.下面是我的代码到目前为止,它似乎大部分时间都有效,但偶尔我在做nct_it ++时会出错.在递增迭代器之前从表中擦除迭代器指针是否安全?
std::list<SinkSourceNodeConn>::iterator it;
std::multimap<SysNode*, SysNode*>::iterator nct_it;
SysNode* found_node = NULL;
nct_it = node_conn_table.begin();
while(nct_it != node_conn_table.end()) {
// Find the node in the ever shrinking node connection table...
if(nct_it->first == parent_node)
found_node = nct_it->second;
// Remove the table entry if we have found a node
if(found_node) {
// Search for the node in the expanded list. If it's not found, add it.
bool found_the_node = false;
for(it = m_sink_source_nodes_.begin(); it != m_sink_source_nodes_.end(); it++) {
if(it->sink_source == sink_source && it->node …Run Code Online (Sandbox Code Playgroud)