public static member function
static const char_type* find (const char_type* p, size_t n, const char_type& c);
Find first occurrence of character
Returns a pointer to the first character in the sequence of n characters pointed by p that compares equal to c.
All character traits types shall implement the function as if the individual characters were compared using member eq.
- Pointer to an array with a sequence of characters.
Notice that the function will consider that the length of the sequences is n characters, independently on whether it contains null-characters or not.
- Length (in characters) of the sequence of characters to compare.
- A character value.
Member type char_type is the character type (i.e., the class template parameter in char_traits).
size_t is an unsigned integral type.
A pointer to the first match, if any, or a null pointer otherwise.
#include <iostream> // std::cout
#include <string> // std::char_traits
int main ()
const char foo = "test string";
const char* p = std::char_traits<char>::find(foo,std::char_traits<char>::length(foo),'i');
if (p) std::cout << "the first 'i' in \"" << foo << "\" is at " << (p-foo) << ".\n";
the first 'i' in "test string" is at 8.
Up to linear in n.
Unless either p does not point to an array long enough, this member function never throws exceptions (no-throw guarantee) in any of the standard specializations.
Otherwise, it causes undefined behavior.