Espacios de nombres
Variantes

std::strchr

De cppreference.com
 
 
 
Cadenas de bytes terminadas en nulo
Funciones
Manipulación de caracteres
Conversiones a formatos numéricos
(C++11)(C++11)
(C++11)(C++11)
Manipulación de cadenas
Examinación de cadenas
Manipulación de memoria
Misceláneos
 
<tbody> </tbody>
Definido en el archivo de encabezado <cstring>
const char *strchr( const char *str, int ch );
  char *strchr( char *str, int ch );
Busca la primera aparición del carácter ch de la cadena de bytes apuntada por str .
Original:
Finds the first occurrence of the character ch in the byte string pointed to by str.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Parámetros

str -
puntero a la cadena de bytes de terminación nula a analizar
Original:
pointer to the null-terminated byte string to be analyzed
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ch -
carácter que desea buscar
Original:
character to search for
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Valor de retorno

Puntero al carácter encontrado en str o NULL si no se encuentra dicho carácter .
Original:
Pointer to the found character in str, or NULL if no such character is found.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Ejemplo

#include <cstring>
#include <iostream>

int main()
{
    const char* str = "Try not. Do, or do not. There is no try.";
    char objetivo = 'T';
    const char* resultado = str;

    while ((resultado = std::strchr(resultado, objetivo)) != nullptr)
    {
        std::cout << "Encontrado '" << objetivo
                  << "' comenzando en '" << resultado << "'\n";

        // Incrementar resultado, en otro caso encontraremos objetivo en la misma ubicación
        ++resultado;
    }
}

Salida:

Encontrado 'T' comenzando en 'Try not. Do, or do not. There is no try.'
Encontrado 'T' comenzando en 'There is no try.'

Ver también

Encuentra la última aparición de un carácter
(función) [editar]
Encuentra la primera ubicación de cualquier carácter en una cadena, en otra cadena
(función) [editar]