Extracting data stored in a map or multimap

hi,

i am using a multimap to store some data. i am able to create the multimap, but when i try to print the data within it, i am only able to print the memory address and not get the value.

reference (section “storing objects in a map”): http://openframeworks.cc/ofBook/chapters/stl_map.html

.h file:

class xyPos {
    public:
    
    float x, y;
    
    xyPos(float xPos, float yPos) {
        x = xPos;
        y = yPos;
    }
    
    //return ofVec2f(x, y);
};

static multimap<string, xyPos> posMap;
static multimap<string, xyPos>::iterator xyMapIterator;

.cpp file:

for(int i = 0; i < 10; i ++) {
for(int j = 0; j < 10; j ++) {
posMap.insert(make_pair(“null”, xyPos(i, j));
}
}

i have also tried:

for(int i = 0; i < 10; i ++) {
for(int j = 0; j < 10; j ++) {
xyPos *p = new xyPos(i, j);
xyMap.insert(make_pair(“null”, *p);
}
}

cout << "xyMap:\n";
for(xyMapIterator = xyMap.begin(); xyMapIterator != xyMap.end(); ++ xyMapIterator) {
    cout << (*xyMapIterator).first << " => " << (*xyMapIterator).second << "\n";
} //will only compile with &(*xyMapIterator).second so i only have ["null", memory address] in the output

answer:

cout << “xyMap:\n”;
for(xyMapIterator = xyMap.begin(); xyMapIterator != xyMap.end(); ++ xyMapIterator) {
cout << (*xyMapIterator).first << " => " << (*xyMapIterator).second.x << " , " << (*xyMapIterator).second.y << “\n”;
}

If you want to write less use auto

for(auto& p:xyMap){
 cout << p.first << " => " << p.second.x << " , " << p.second.y << "\n";
}

thanks, roy.

i have used that as well, but since i didn’t know where my problem was, i wrote it out the long way (even though i knew that wasn’t the problem) anyway.

01