我是一名有用的助手,可以为您翻译文本。
我想从一个映射中删除一个键值对,但我的问题是我只有值,而没有键。如何使用“值”从映射中删除一个键值对。并且我拥有的值在映射中是唯一的。
以下是我的代码片段:
这会删除键值对吗?
我想从一个映射中删除一个键值对,但我的问题是我只有值,而没有键。如何使用“值”从映射中删除一个键值对。并且我拥有的值在映射中是唯一的。
以下是我的代码片段:
int Clientqueues::addClient(string ipaddress, string sessionid)
{
clientsWithNoLogin.insert(pair<string,string>(ipaddress,sessionid));
return 0;
}
void Clientqueues::deleteClient(string sessionid)
{
map<string, string>::iterator i,current;
for(i = clientsWithNoLogin.begin() ;i!= clientsWithNoLogin.end();)
{
current = i;
++i;
if((current->second) == sessionid) clientsWithNoLogin.erase(current);
}
return ;
}
这会删除键值对吗?