How to find minimum value from vector?

See std::min_element.

Examples:

std::min_element(vec.begin(), vec.end()); // STL containers.
std::min_element(v, v + n); // C style arrays where n is the number of elements.
std::min_element(std::begin(v), std::end(v)); // STL containers and C style arrays. 

Note that for the last option, it is better to apply the ‘std 2-step’ pattern so it works for user-defined types as well as standard library types:

using std::begin, std::end; // Enables argument-dependent lookup: https://en.cppreference.com/w/cpp/language/adl
std::min_element(begin(v), end(v));

Since C++20, we can also use ranges to avoid having to call begin/end manually:

std::ranges::min_element(v);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)