STL - Algorithm/Algorithm - Non-Modifying
Algorithm - count_if()
Programmer.
2016. 2. 7. 16:17
소스)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include<vector> #include<iostream> #include<algorithm> bool count_comp(int i) { if (i < 7) return true; return false; } void main() { std::vector<int> Vector = { 1, 3, 5, 7, 9, 11, 13, 15 }; std::cout << std::count_if(Vector.begin(), Vector.end(), count_comp) << std::endl; } | cs |
내용)
count_if(x,y,z) 함수는 iterator x가 가리키는 위치부터 iterator y가 가리키는 위치 사이에 있는 데이터들 중에서 z에 만족하는 값들의 갯수를 세서 리턴합니다.
결과)