[Solved] C++’s min_element() not working for array [closed]


Note, that std::min_element() returns an iterator to a minimal value, not the value itself. I doubt that you get this error based on the above code alone: assuming proper include directives and using directives the code compiles OK although it would print the address of the minimum element rather than its value. Most likely your actual code looks more like

unsigned min = std::min_element(w + a, w + b);

Note, that you should also check the result of reading from std::cin:

if (std::cin >> n >> a >> b) {
   // process the values
}

… and, of course, it seems you’re leaking the memory allocated for w.

4

solved C++’s min_element() not working for array [closed]