我宣布地图:
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
}
}
//然后通过套接字发送
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);
}