Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: C++
Expertise: Intermediate
Feb 12, 1999



Application Security Testing: An Integral Part of DevOps

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 <algorithm> //  definition of find()
#include <list>
#include <iostream>
using namespace std;
int main()
  list<char> lc;

  list<char>::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
Danny Kalev
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date