Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ find object in vector by attribute

std::vector<Type> v = ....;
std::string myString = ....;
auto it = find_if(v.begin(), v.end(), [&myString](const Type& obj) {return obj.getName() == myString;})

if (it != v.end())
{
  // found element. it is an iterator to the first matching element.
  // if you really need the index, you can also get it:
  auto index = std::distance(v.begin(), it);
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to initialize 2d array with values c++ 
Cpp :: c++ split string by space into array 
Cpp :: c++ switch statement 
Cpp :: cpp define function 
Cpp :: SUMOFPROD2 
Cpp :: Give an algorithm for finding the ith-to-last node in a singly linked list in which the last node is indicated by a null next reference. 
Cpp :: maxheap cpp stl 
Cpp :: c++ get whole line 
Cpp :: vectors c++ 
Cpp :: how to format decimal palces in c++ 
Cpp :: how to replace part of string with new string c++ 
Cpp :: length of a string c++ 
Cpp :: lambda function in c++ 
Cpp :: overload subscript operator cpp 
Cpp :: c++ forbids comparison between pointer and integer 
Cpp :: cyclic array rotation in cpp 
Cpp :: set of vectors c++ 
Cpp :: Syntax for C++ Operator Overloading 
Cpp :: program to swap max and min in matrix 
Cpp :: what library is rand in c++ 
Cpp :: even and odd in c++ 
Cpp :: call function from separate bash script 
Cpp :: c++ split string 
Cpp :: pow without math.h 
Cpp :: executing an opencv c++ code 
Cpp :: sum of n natural numbers 
Cpp :: How to generate all the possible subsets of a set ? 
Cpp :: c++ threadpool 
Cpp :: error in c++ 
Cpp :: how to show constellations in starry night orion special edition 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =