Comment valider si tous les caractères étirés dans une chaîne sont des alphabets, puis repropriser l'utilisateur

#include <iostream>
#include <string>
#include <cctype>

// check for only alphabetical letters in string (or spaces)
bool lettersOrSpaces(const std::string& str)
{
    for (size_t i = 0; i < str.size(); i++)
    {
        // make sure each character is A-Z or a space
        if (! std::isalpha(str[i]) && ! std::isspace(str[i]))
        {
            return false; ///< at least one "no match"
        }
    }
    return true;  ///< all characters meet criteria
}

int main()
{
    std::string townName;
    std::cout << "Enter name of town: ";
    while (std::getline(std::cin, townName) && !lettersOrSpaces(townName))
    {
        std::cout << "Enter the town name - alphabet only: ";
    }
    std::cout << "The name of town is: " << townName << std::endl;

    return 0;
}
Blue Bear