getting certain component of all elements in vector

Viewed 147

I have stored some elements of a struct, let's call it myStruct, in a vector. Now I want to get a certain component of this struct of all the elements in my vector.

Is there a possibility to do this fast, without using a for-loop? Is there an equivalent solution for deque?

struct myStruct{
    int a;
    int b;
};

vector<myStruct> vec;

//creating some data and push back to vector
myStruct ms0,ms1;
ms0.a = 5;
ms1.a = 10;             
vec.push_back(ms0);
vec.push_back(ms1);

//now I want to get the component a of ms0 and ms1
3 Answers
Related