c++ check if char is letter code example
Example 1: check if character in string is alphabet c++
#include<stdio.h>
#include<ctype.h>
int main() {
char val1 = 's';
char val2 = '8';
if(isalpha(val1))
printf("The character is an alphabet\n");
else
printf("The character is not an alphabet\n");
if(isalpha(val2))
printf("The character is an alphabet\n");
else
printf("The character is not an alphabet");
return 0;
}
Example 2: check if character in string c++
std::string s = "hell[o";
if (s.find('[') != std::string::npos)
;
else
;
Example 3: c++ check if char is number
char c = '1';
bool result = isdigit(c);
cout << result << endl;
Example 4: isalpha c++
char test='a';
cout<<isalpha(test);