Share via


char_traits::find

Buscar la primera aparición de un carácter especificado en un intervalo de caracteres.

static const char_type* find(
   const char_type* _Str, 
   size_t _Num, 
   const char_type& _Ch 
);

Parámetros

  • _Str
    El primer carácter de la cadena que se buscará.

  • _Num
    El número de posiciones, contando de primer, en el intervalo que se buscará.

  • _Ch
    El carácter que se buscará en el intervalo.

Valor devuelto

Un puntero a la primera aparición del carácter especificado en el intervalo si se encuentra una coincidencia; si no, un puntero NULL.

Ejemplo

// char_traits_find.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

int main( ) 
{
   using namespace std;

   const char* s1 = "f2d-1234-abcd";
   const char* result1;
   cout << "The string to be searched is: " << s1 << endl;

   // Searching for a 'd' in the first 6 positions of string s1
   result1 = char_traits<char>::find ( s1 , 6 , 'd');
   cout << "The character searched for in s1 is: "
        << *result1 << endl;
   cout << "The string beginning with the first occurrence\n "
        << "of the character 'd' is: " << result1 << endl;

   // When no match is found the NULL value is returned
   const char* result2;
   result2 = char_traits<char>::find ( s1 , 3 , 'a');
   if ( result2 == NULL )
      cout << "The result2 of the search is NULL." << endl;
   else
      cout << "The result2 of the search  is: " << result1
           << endl;
}
  

Requisitos

encabezado: <cadena>

espacio de nombres: std

Vea también

Referencia

char_traits Struct