Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a 2-Dimensional vector with columns serial no and names,
I wanted to find all elements matching with a certain keyword in names column and filter data accordingly..


Example
1 XXX
2 bbb
3 xxx
4 aaa

now in this vector if i search for xxx i should get elements position matching with my keyword.

Is there any predefined functions do that??,,

I can find it using each element comparison but i am looking advanced solution.

Can any one suggest me an idea..
Posted
Comments
Legor 15-May-14 3:48am    
You didnt say how you store this data. Do you store it in a std::vector or a std::map or something else? Of course there are given functions for searching an item in a collection but it depends on the type of collection you store your data in. E.g. for your example a std::map may be helpful.
P Uday kishore 19-May-14 0:39am    
am using vector.pushback to store the elements.

1 solution

You can use the std::find algorithm of STL.
http://www.cplusplus.com/reference/algorithm/find/[^]
http://en.cppreference.com/w/cpp/algorithm/find[^]
It will return the iterator to the element found.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900