How do I find an element position in std::vector?

前端 未结 10 1960
情深已故
情深已故 2021-01-31 08:40

I need to find an element position in an std::vector to use it for referencing an element in another vector:

int find( const vector& whe         


        
10条回答
  •  灰色年华
    2021-01-31 08:46

    You could use std::numeric_limits::max() for elements that was not found. It is a valid value, but it is impossible to create container with such max index. If std::vector has size equal to std::numeric_limits::max(), then maximum allowed index will be (std::numeric_limits::max()-1), since elements counted from 0.

提交回复
热议问题