Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Extracting data stored in a map or multimap

$
0
0

@robotPatrol wrote:

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

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Latest Images

Trending Articles



Latest Images