Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created June 20, 2019 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/68e9d38304a1f0831a5e7d7a71231bd7 to your computer and use it in GitHub Desktop.
Save parzibyte/68e9d38304a1f0831a5e7d7a71231bd7 to your computer and use it in GitHub Desktop.
std::string nombres[] = {
"Luis", "Marijo", "Paco", "Pedro",
};
std::string busqueda = "Luis";
int indice = -1;
for (int i = 0; i < sizeof(nombres) / sizeof(nombres[0]); i++) {
std::string nombreActual = nombres[i];
if (nombreActual == busqueda) {
indice = i;
break;
}
}
if (indice == -1) {
std::cout << "No encontrado\n";
} else {
std::cout << "Encontrado en el indice " << indice << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment