Segmentation fault trying to dereference an iterator

前端 未结 1 638
无人共我
无人共我 2021-01-26 06:25

I\'m trying to find the maximum value of a vector using std::max_element. When I run the program I get a segmentation fault that I believe is to do with std::end going over the

相关标签:
1条回答
  • 2021-01-26 07:13

    It won't work when max is std::end(tempdata) which can occurs if your tempdata is empty.

    Iterator to the greatest element in the range [first, last). If several elements in the range are equivalent to the greatest element, returns the iterator to the first such element. Returns last if the range is empty.

    source

    0 讨论(0)
提交回复
热议问题