本文介绍了C ++如何检查字母isalpha(不是拉丁字母)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我需要看看我的角色是否是字母。我尝试使用isalpha()函数,但是,如果我尝试不传递拉丁字母(例如,±,č,ę,ė,į,š,ų,ū,ž),则会出现错误,似乎表明isalpha函数仅接受ASCII码在0到255之间的字符。有什么方法可以解决此问题?
so I need to see if my character is a letter. I tried using isalpha() function, however, if I try to pass not latin letter (for example ą, č, ę, ė, į, š, ų, ū, ž) I get an error, that seems to state that isalpha function accepts only chars that in ASCII code are between 0 and 255. Is there any way to overcome this problem?
推荐答案
您可以使用的语言环境版本。从链接的引用中获取示例:
You can use a locale version of std::isalpha
. Taking an example from the linked reference:
#include <iostream>
#include <locale>
int main()
{
const wchar_t c = L'\u042f'; // cyrillic capital letter ya
std::locale loc1("C");
std::cout << "isalpha('Я', C locale) returned "
<< std::boolalpha << std::isalpha(c, loc1) << '\n';
std::locale loc2("en_US.UTF8");
std::cout << "isalpha('Я', Unicode locale) returned "
<< std::boolalpha << std::isalpha(c, loc2) << '\n';
}
输出:
isalpha('Я', C locale) returned false
isalpha('Я', Unicode locale) returned true
这篇关于C ++如何检查字母isalpha(不是拉丁字母)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!