#include <iostream>
#include <cctype>
bool CheckString(std::string str)
{
bool good{ true };
for (size_t lc = 0; lc < str.length(); lc++)
{
if (std::isspace(str[lc])) // <--- Checks for spaces.
;
elseif (std::ispunct(str[lc])) // <--- Checks for punction characters.
;
elseif (!(std::isalpha(str[lc])))
{
std::cout << "Error message" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(3)); // Requires header files "chrono" and "thread"
returnfalse;
}
}
return good;
}
int main()
{
std::string str{ "This is a string" };
//std::string str{ "Th1s is a string" };
if (CheckString(str))
std::cout << "The string is good" << std::endl;
return 0;
}
This could likely be shortened, but I did not have the time to work on it. Some of what is in the function is there more for ideas of what can be done.