Skip to content

Instantly share code, notes, and snippets.

@mochow13
Last active September 12, 2018 08:00
Show Gist options
  • Save mochow13/b2954dcf1f95a2ccfb064fce7ba5b885 to your computer and use it in GitHub Desktop.
Save mochow13/b2954dcf1f95a2ccfb064fce7ba5b885 to your computer and use it in GitHub Desktop.
std::vector<int> collection={1,9,9,4,2,6};
// How many 9s are there in collection?
int nines=std::count(begin(collection),end(collection),9);
// How many elements of the collection are even?
int evens=std::count_if(begin(collection),end(collection),[](int x) {
return x%2==0;
});
// nines equals 2, evens equals 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment