[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppMinElement
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppMinElement
(C++) std::min_element
STL algorithm to find the lowest element in a sequence (e.g. a std::vector).void myCout(const int& i) { std::cout << i << std::endl; } void myRand(int& i) { i = std::rand()%100; } int main() { std::vector<int> v(10); std::for_each(v.begin(),v.end(),myRand); std::for_each(v.begin(),v.end(),myCout); std::cout << "-----" << std::endl; const int i = *(std::min_element(v.begin(),v.end())); const int a = *(std::max_element(v.begin(),v.end())); std::cout << i << std::endl; std::cout << a << std::endl; std::cin.get(); }
- include <iostream>
- include <vector>
- include <algorithm>
Related links
Code links
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
