Getting started
Literals
Basic type keywords
Operator precedence
Floating point arithmetic
Bit operators
Bit manipulation
Bit fields
Arrays
Flow control
const keyword
Loops
mutable keyword
friend keyword
keywords
Variable declaration keywords
auto keyword
Pointers
Type keywords (class, enum, struct, union)
Classes / structs
std::string
Enumeration
std::atomic<T>
std::vector
std::array
std::pair
std::map
std::unordered_map
std::set and std::multiset
std::any
std::variant
std::optional
std::integer_sequence
std::function
std::forward_list
std::iomanip
Iterators
Basic I/O
File I/O
Streams
Stream manipulators
Metaprogramming
Returning multiple values from a function
References
Polymorphism
Value and reference semantics
Function call by value vs. by reference
Copying vs assignment
Pointers to class / struct members
The this pointer
Smart pointers
Unions
Templates
Namespaces
Function overloading
Operator overloading
Lambdas
Threading
Value categories
Preprocessor
SFINAE
Rule of three, five and zero
RAII
Exceptions
Implementation-defined behavior
Special member functions
Random numbers
Sorting
Regular expressions
Perfect forwarding
Virtual member functions
Undefined behavior
Overload resolution
Move semantics
Pimpl idiom
Copy elision
Fold expressions
Unnamed types
Singleton
ISO C++ Standard
User-defined literals
Type erasure
Memory management
Explicit type conversions
RTTI
Standard library algorithms
Standard Library Algorithms
std next permutation
std for each
std accumulate
std find
std count
std count if
std find if
std min element
Using std nth element To Find The Median Or Other Quantiles
Expression templates
Scopes
Atomic types
static assert
constexpr
Date and time with std::chrono
Trailing return type
Function template overloading
Common compile linker errors
Design patterns
Optimizations
Compiling and building
Type traits
One definition rule
Unspecified behavio
Argument dependent name lookup
Attributes
Internationalization
Profiling
Return type covariance
Non-static member functions
Recursion
Callable objects
Constant class member functions
C++ vs. C++ 11 vs C++ 17
Inline functions
Client server examples
Header files
Const correctness
Refactoring techniques
Parameter packs
Iteration
type deduction
C++ 11 memory model
Build systems
Concurrency with OpenMP
Type inference
Resource management
Storage class specifiers
Alignment
Inline variables
Linkage specifications
Curiusly recurring template pattern
Using declaration
Typedef and type aliases
Layout of object types
C incompatibilities
Optimization
Semaphore
Thread synchronization
Debugging
Futures and promises
More undefined behaviors
Mutexes
Recursive mutex
Unit testing
decltype
Digit separators
C++ Containers
Arithmetic meta-programming
Contributors

std find

suggest change
template <class InputIterator, class T>
InputIterator find (InputIterator first, InputIterator last, const T& val);

Effects

Finds the first occurrence of val within the range [first, last)

Parameters

first => iterator pointing to the beginning of the range last => iterator pointing to the end of the range val => The value to find within the range

Return

An iterator that points to the first element within the range that is equal(==) to val, the iterator points to last if val is not found.

Example

#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {

  //create a vector
  vector<int> intVec {4, 6, 8, 9, 10, 30, 55,100, 45, 2, 4, 7, 9, 43, 48};

  //define iterators
  vector<int>::iterator  itr_9; 
  vector<int>::iterator  itr_43; 
  vector<int>::iterator  itr_50; 

  //calling find
  itr_9 = find(intVec.begin(), intVec.end(), 9); //occurs twice
  itr_43 = find(intVec.begin(), intVec.end(), 43); //occurs once

  //a value not in the vector
  itr_50 = find(intVec.begin(), intVec.end(), 50); //does not occur
cout << "first occurence of: " << *itr_9 << endl;
cout << "only occurence of: " << *itr_43 << Lendl;
/*
  let's prove that itr_9 is pointing to the first occurence
  of 9 by looking at the element after 9, which should be 10 
  not 43
*/
cout << "element after first 9: " << *(itr_9 + 1) << ends;

/*
  to avoid dereferencing intVec.end(), lets look at the 
  element right before the end
*/
cout << "last element: " << *(itr_50 - 1) << endl;
return 0;
}

Output

first occurence of: 9
only occurence of: 43
element after first 9: 10
last element: 48

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents
12 Loops
52 Unions
61 SFINAE
63 RAII
85 RTTI
88 Scopes
140 Mutexes