I have small piece of code to print smallest element in the range using std::min_element. cppreference example print the index of smallest element, but i want to print smallest element instead of index number.
#include <algorithm>
#include <iostream>
#include <vector>
int main()
{
std::vector<int> v{3, 1, 4, 1, -5, 9};
std::cout << std::min_element(std::begin(v), std::end(v));
}
But, I got following an error:
main.cpp: In function 'int main()':
main.cpp:8:15: error: no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and '__gnu_cxx::__normal_iterator<int*, std::vector<int> >')
std::cout << std::min_element(std::begin(v), std::end(v));
So, What's the wrong with my code?