A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/string/char_traits/find/ below:

public static member function

<string>

std::char_traits::find
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.



Parameters
p
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.
n
Length (in characters) of the sequence of characters to compare.
c
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.

Return Value A pointer to the first match, if any, or a null pointer otherwise.

Example
1
2
3
4
5
6
7
8
9
10
11
// char_traits::find
#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";
  return 0;
}

Output:
the first 'i' in "test string" is at 8.


Complexity Up to linear in n.

Exception safety 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.

See also
char_traits::compare
Compare sequences of characters (public static member function)
char_traits::eq
Compare characters for equality (public static member function)
string::find
Find content in string (public member function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4