Count word frequencies, and print them most-frequent first
Mainly this looks fine.

using namespace std; is a bad habit to get into due to potential name collisions. Instead prefer to type std:: where necessary.

counts[word]++;. We don't need an un-incremented copy of the count, so we should use pre-increment here instead: ++counts[word];

sort(ordered.begin(), ordered.end(), [](auto &amp;a, auto &amp;b) we don't alter a or b in the lambda, so these should be const&amp;.

for (auto count : ordered) copies the pairs. Again, we should be using auto const&amp; here.

return 0; we don't need this, as the compiler will add it for us automatically. We might also use a named constant instead of 0, specifically EXIT_SUCCESS from &lt;cstdlib&gt;.