I have a vector of type string which contains the following:
tpNums contains: 2 15 38 43 50 5 14 16 29 53
I am attempting to take the contents of the vector and count the number of times each number in the vector appears in this case they all only appear once; following code:
std::map<std::string, std::size_t> results;
std::for_each(begin(tpNums), end(tpNums), [&](std::string const& s)
{
++results[s];
});
My question is, how do I output the contents of the resultant map?
Is there an easier to solve my problem or is this the only way?
EDIT:
I have tried this:
std::map<std::string, std::size_t> results;
std::for_each(begin(tpNums), end(tpNums), [&](std::string const& s)
{
++results[s];
cout << results[s];
});
OUTPUT:1112
I don't think I am outputting the correct thing, I have tried different ways but they either show an error or output the wrong thing