这里我使用了多重映射并在底部打印了它的内容。
通常我只使用数组并轻松返回和获取数组内容。
喜欢:
void main(){
char *ch;
ch=client(); //function call
//Now we can get ch[0]...
}
char function client()
{
char ar[2]
....
return ar;
}
我可以以类似的方式处理多重 map 吗?因为我想同时返回 string 和 int 值。并使用套接字编程,因此它将使用 send 和 receive() 方法来发送和接收。
std::multimap<int,std::string>::iterator it = dst.begin();
for(int count = 0;count<3 && it !=dst.end();++it,++count)
std::cout<<it->second<<":"<<it->first<<std::endl;
在此代码中,我想发送it->second
和it->first
。
什么是正确的方法?
最佳答案
是的,这会起作用,但更喜欢使用 const ierator。正如 const 所建议的(至少在最近的编译器和库中)也是线程安全的。所以更喜欢:
std::multimap<int,std::string>::const_iterator it = dst.cbegin();
for(int count = 0;count<3 && it !=dst.cend();++it,++count)
std::cout<<it->second<<":"<<it->first<<std::endl;
关于c++ - 返回多重映射的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18557265/