I have a std::map in my program which stores pairs of values. I want the keys in the map to be unique - which is the expected behavior of a std::map class. But when I insert the pairs into it, some keys are repeated. How do I solve this problem?
My code is as follows:
map<float,vector<float> *> inpDataMap;
inpDataMap.clear();
for(int i = 0; i < input.getNum(); i++)
{
float xVal = input[i][0];
float yVal = input[i][1];
if(inpDataMap.count(xVal) > 0)
{
myfile << i << " repeated xval: " << xVal << " : " << yVal << endl;
inpDataMap[xVal]->push_back(yVal);
myfile << "repeated value pushed" << endl;
}
else
{
vector<float> *inVec = new vector<float>;
inVec->push_back(yVal);
inpDataMap[xVal] = inVec;
myfile << i << " not repeated:" << xVal << ":" << yVal << endl;
}
}
As you can see that the map I have here is actually an association of a float and a vector of associated floats. If there's already a key existing, the value is added to the vector corresponding to that key. But like I said, the keys are not stored uniquely. Can anybody help me to solve this problem?
Rakesh.