Locate an Element of a Container Using the find() Algorithm

Locate an Element of a Container Using the find() Algorithm

You can use the generic algorithm find() to locate an element of a container. The find() algorithm takes three arguments. The first two are iterators that point at the beginning and the end of the sequence, respectively. The third argument is the sought after value. The find() algorithm returns an iterator pointing to the first element that is identical to the sought after value. If find() cannot locate the requested value, it returns an iterator pointing one element past the final element in the sequence (that is, it returns the same value as end() does). For example:

 #include  //  definition of find()#include #include using namespace std;int main(){  list lc;  lc.push_back('A');  lc.push_back('T');  lc.push_back('L');  list::iterator p = find(lc.begin(), lc.end(), 'A');   // find 'A'  if (p != lc.end())     // was A found?     *p = 'S';    // replace 'A' with 'S'	  while (p != lc.end())    //display the modified list	  cout<<*p++;}
Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular