【C++】条件を満たす要素の数を取得
#include <iostream> #include <algorithm> int _tmain(int argc, _TCHAR* argv[]) { int i[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; int n = std::count_if(std::begin(i), std::end(i), [](int x){ return x % 3 == 0; }); std::cout << n << std::endl; // 3 return 0; }