我已经声明了地图:
std::map <std::string, int> mymap;
我想在上面的地图中插入两个值,
*vit
然后hit->first
通过套接字发送和接收。
我的代码:
for (std::map < int, std::vector < std::string > >::iterator hit = three_highest.begin(); hit != three_highest.end(); ++hit) {
for (std::vector < std::string >::iterator vit = (*hit).second.begin(); vit != (*hit).second.end(); vit++) {
std::cout << hit->first << ":";
std::cout << *vit << "\n";
mymap.insert( std::pair<std::string,int> (*vit,hit->first)); //Is it correct way
}
}
//然后通过socket发送
if ((bytecount = send(*csock, mymap , sizeof(mymap), 0)) == -1) { // I think this is wrong, Can someone correct it?
fprintf(stderr, "Error sending data %d\n", errno);
goto FINISH;
}
在接收端如何取回这两个变量?
std::map <std::string, int> mymap;
if((bytecount = recv(hsock, mymap, sizeof(mymap), 0))== -1){ //Needs help here also
// getting mymap->first, mymap->second.
fprintf(stderr, "Error receiving data %d\n", errno);
}