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

前端 未结 10 1892
情深已故
情深已故 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 09:05

    You probably should not use your own function here. Use find() from STL.

    Example:

    list L;
    L.push_back(3);
    L.push_back(1);
    L.push_back(7);

    list::iterator result = find(L.begin(), L.end(), 7); assert(result == L.end() || *result == 7);

提交回复
热议问题