how to access a value?

i'm trying to access the x, y, z values in a vector.
the driver of the sensor sets things up like this...

cloud2_.height = height_;
cloud2_.width = width_;
cloud2_.fields.resize (5);
cloud2_.fields[0].name = "x";
cloud2_.fields[1].name = "y";
cloud2_.fields[2].name = "z";
cloud2_.fields[3].name = "rgb";
cloud2_.fields[4].name = "intensity";

'cout << cloudName->height' will give me the height value, same with 'width'

but how can i get the value for x y or z?

'cout << cloudName->fields[0]' will show a bunch of stuff but not the actual value?

any ideas?
How about:

cout << cloudName->fields[0].name
have you tried cloudName->x?
cout << cloudName->fields[0].name
returns 'x'


cloudName->x
returns 'error: no member named x'


thanks for the suggestions! keep em' coming :)
I thought that's what you wanted it to return. 'x'.
Last edited on
yes, correct but i want the value not just the letter.

just like if i put cloudName->height, it returns 160 or whatever the height is.
But "x" is a string value belonging to the element name. x is not an element itself. There isn't an element named x that stores a value.
You need to look for the type of the elements contained in fields.

Presumably, fields[x] contain other data members than just a name, or they wouldn't be particularly useful. I would guess one of those other data members is what you want to be accessing.
Topic archived. No new replies allowed.