Is there a built in function that will search for all occurances of a letter or number in an array? I know I could create one using a for loop but is there anything that will already do this?
Printable View
Is there a built in function that will search for all occurances of a letter or number in an array? I know I could create one using a for loop but is there anything that will already do this?
not to my knowledge...
however, you can come close with a combination of functions:
Code:vector<string> array;
for (vector<string>::iterator i = array.begin(); i != array.end(); ++i)
if ((*i).find("K",0) != string::npos)
; //do whatever in the conditition that the match has been found
There is std::find you pass an iterator(pointer) to the start and one past the end, it returns the first element found or the pointer to one past the end if not found.
int arr[] ={2,5,3,4,9}
int *p = std::find(arr,&arr[sizeof(arr)],4);
p==&arr[3];
p = std::find(arr,&arr[sizeof(arr)],8);
p==&arr[sizeof(arr)]
vectors and strings provide faster and more usefull specializations.