-2

I am trying to construct a map that maps a string to a vector of unsigned integers. The way that I construct this map is as follows:

void PixelP1ROCDACSettings::getDACs(map<string,vector<unsigned int>>& dacs) const
{
    dacs.clear();
    dacs.insert(pair<string, vector<unsigned int> > (k_DACName_Vdd, make_vector(Vdd_, k_DACAddress_Vdd)));
    dacs.insert(pair<string, vector<unsigned int> > (k_DACName_Vana,make_vector(Vana_, k_DACAddress_Vana)));
    ...
}

Where make_vector is defined as follows:

   std::vector<unsigned int> make_vector(unsigned int DACValue, 
                                         unsigned int DACAddress) const ;

My questions are: 1) I would like to get access each individual value in my vector, I've tried to do, dacs[key][index] but that didn't seem to work. Is there a special syntax to do this?

2) Additionally, I would like to iterate across my map, How would I do that?

Thanks in advance.

RN_
  • 878
  • 2
  • 11
  • 30
Justin
  • 1
  • possibly related : http://stackoverflow.com/questions/1380585/map-of-vectors-in-stl – RN_ Jul 01 '15 at 16:19
  • `dacs[key][index]` should work, can you give more details on why it is not working? Iterating over map: http://stackoverflow.com/questions/4844886/how-to-loop-through-a-c-map – ssemilla Jul 01 '15 at 16:21

1 Answers1

0

If you are using c++11 you can iterate with

for (auto& keyvaluepair : dacs) {
     //keyvaluepair.first is your string
     //keyvaluepair.second is your vector
}

also dacs[key][index] is the correct way to access the indexth element in the vector mapped to by key.

  • I implemented your suggestion but now I am getting the following error: >src/common/PixelFECInterface.cc:2674: error: expected initializer before ‘:’ token – Justin Jul 01 '15 at 17:34