Hello, I need some help with vectors . . . again. I am pushing component "types" from one vector into another vector. That part is fine. Then what I'm trying to do is take the items in the new vector and "weed out" the duplicate entries by pushing unique values into, yet, another vector. For some reason, it's pushing some of the duplicate items in the newest vector anyway. Here is my code. NOTE: Not all of the code is listed here, just the little part I am having trouble with so the {} may not all add up. Any help is greatly appreciated.
Code:
int total = static_cast<int>(vComp.size()) - 1; int tTotalUnits = 0; float tTotalCostJob = 0; int i = 0; int j = 0; int counter = 0; bool foundFlag; vector<string> vItems; vector<string> vHolding; for(i = 0; i < total; ++i) { // Push components into the vItems vector vHolding.push_back(vComp[i].GetType()); if(vItems.empty()) { vItems.push_back(vComp[i].GetType()); } for (j = 0; j < vItems.size(); j++) { if(vHolding[i] == vItems[j]) { foundFlag = true; } else { foundFlag = false; } } if(foundFlag == false) { vItems.push_back(vHolding[i]); } }
Comment