1

Say I have a class myClass with 3 attributes in the constructor (string value, int pos, int pos_2).

Now I make a vector of objects of said class.

How would I search through vector<myClass> to find the index of any class objects with a string that matches a given string?


Example:

Here's a (non-functional) attempt at finding a class object that has the string hello as its string value:

std::string to_find = "hello";
std::vector<myClass>::iterator duplicate_it;
duplicate_it = std::find(subrelation_vector.begin()->value, subrelation_vector.end()->value, to_find);
int duplicate_pos = *duplicate_it->pos;
velkoon
  • 871
  • 3
  • 15
  • 35
  • Use `std::map` or `std::multimap` per attribute for more quick search. The values of map and vector for this case better make as std::shared_ptr – oklas Mar 06 '16 at 10:46

0 Answers0