void checkTarget() { int target = 14; int buf[] = { 8, 2, 9, 10, 5, 4, 6 }; std::map<int, int> tmpMap; for (int i = 0; i < sizeof(buf); i ++) { std::map<int, int>::iterator itor = tmpMap.find(target - buf[i]); if (itor == tmpMap.end()) { tmpMap.insert(pair<int, int>(buf[i], i)); } else { int index1 = itor->second; int index2 = i; cout << index1 << ":" << index2 << endl; break; } } }