Using C++11/C++0x compile flags, you can
auto it = max_element(std::begin(cloud), std::end(cloud)); // C++11
Otherwise, write your own:
template <typename T, size_t N> const T* mybegin(const T (&a)[N]) { return a; }
template <typename T, size_t N> const T* myend (const T (&a)[N]) { return a+N; }
See it live at http://ideone.com/aDkhW:
#include <iostream>
#include <algorithm>
template <typename T, size_t N> const T* mybegin(const T (&a)[N]) { return a; }
template <typename T, size_t N> const T* myend (const T (&a)[N]) { return a+N; }
int main()
{
const int cloud[] = { 1,2,3,4,-7,999,5,6 };
std::cout << *std::max_element(mybegin(cloud), myend(cloud)) << '
';
std::cout << *std::min_element(mybegin(cloud), myend(cloud)) << '
';
}
Oh, and use std::minmax_element(...)
if you need both at once :/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…