I only found information about this topic using C#, and i'm using C++. Hope you can help me with this.
My code:
#include <iostream>
#include <fstream> // Librería para el manejo de archivos
#include <string> // Librería para el manejo de strings
#include <stdlib.h> // Librería para el uso de system("cls");
int main()
{
//Variables
string NombreJugador;
/* Content
------------------------------------------------------------------------*/
do
{
cout << "Your name: ";
cin >> NombreJugador;
} while(ValidarNombreJugador(NombreJugador));
return 0;
}
/* Function
------------------------------------------------------------------------*/
int ValidarNombreJugador(string NombreJugador)
{
int Numero;
Numero = atoi(NombreJugador.c_str());
if (Numero!=0)
{
cout << "No puede ingresar numeros, solo letras." << endl;
return 1;
}
else
{
cout << "Perfecto, tu nombre no tiene numeros." << endl;
return 0;
}
}
I have found on Google this way to validate that the name only have letters and not numbers.
The problem is that if you enter "0", it recognize it as a letter, a mean, it returns true.
What should I do to properly validate that the string has only letters and not numbers?.
I'm new using string by the way.