I am trying to change my code to use something other than structured data as my system does not support the new C++ version. However every time I try to apply a different technique, main one is traditional looping, it either does not work, or gives me an incorrect output.
this is my original code:
std::unordered_map < std::string, std::unordered_map < std::string, int >> wordCounts;
for (const auto & [outerKey, innerMap]: wordCounts) {
for (const auto & [innerKey, count]: innerMap) {
if (innerKey == word && count > 0) {
articlesAppeardIn++;
}
}
}
this is what i tried changing it to
std::unordered_map < std::string, std::unordered_map < std::string, int >> wordCounts;
for (auto outer_pair : wordCounts) {
for (auto inner_pair : outer_pair.second) {
if (inner_pair.first == word && inner_pair.second > 0) {
articlesAppearedIn++;
}
}
}
But it gives me complete different results to the first on (which gives me correct output). I fail to see why it gives me a different output.
I tried changing the implementation to a different more traditional approach of loops, and expected the same result, however I receive completely different results to the first approach used.
Fawaz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1