C++ a map to a 2 dimensional vector

Posted by user1701545 on Stack Overflow See other posts from Stack Overflow or by user1701545
Published on 2012-09-26T21:30:21Z Indexed on 2012/09/26 21:37 UTC
Read the original article Hit count: 135

Filed under:

I want to create a C++ map where key is, say, int and value is a 2-D vector of double: map > > myMap;

suppose I filled it and now I would like to update the second vector mapped by each key (for example divide each element by 2). How would I access that vector iteratively? The "itr->second[0]" syntax in the statement below is obviously wrong. What would be the right syntax for that action?

for(std::map<in, vector<vector<double> > > itr = myMap.begin(); itr != myMap.end();++itr)
{
    for(int i = 0;i < itr->second[0].size();++i)
    {
         itr->second[0][i] /= 2;
    }
}

thanks, rubi

© Stack Overflow or respective owner

Related posts about c++