I was going through techiedelight article link
I didn't get the meaning of [&m](char &c) { m[c]++; }
in std::for_each(s.begin(), s.end(), [&m](char &c) { m[c]++; });
#include <iostream>
#include <unordered_map>
#include <algorithm>
int main()
{
std::unordered_map<char, int> m;
std::string s("abcba");
std::for_each(s.begin(), s.end(), [&m](char &c) { m[c]++; });
char ch = 's';
if (m.find(ch) != m.end()) {
std::cout << "Key found";
}
else {
std::cout << "Key not found";
}
return 0;
}
Someone please explain how it is working. Thanks in advance.