C++ How to check if letter isalpha (not latin alphabet)(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?
推荐答案
您可以使用 locale 版本的 std::isalpha
.以链接参考中的示例为例:
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) << '
';
std::locale loc2("en_US.UTF8");
std::cout << "isalpha('Я', Unicode locale) returned "
<< std::boolalpha << std::isalpha(c, loc2) << '
';
}
输出:
isalpha('Я', C locale) returned false
isalpha('Я', Unicode locale) returned true
这篇关于C++如何检查字母isalpha(不是拉丁字母)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++如何检查字母isalpha(不是拉丁字母)


- 将函数的返回值分配给引用 C++? 2022-01-01
- GDB 不显示函数名 2022-01-01
- XML Schema 到 C++ 类 2022-01-01
- 使用 __stdcall & 调用 DLLVS2013 中的 GetProcAddress() 2021-01-01
- DoEvents 等效于 C++? 2021-01-01
- 将 hdc 内容复制到位图 2022-09-04
- 哪个更快:if (bool) 或 if(int)? 2022-01-01
- 从父 CMakeLists.txt 覆盖 CMake 中的默认选项(...)值 2021-01-01
- OpenGL 对象的 RAII 包装器 2021-01-01
- 如何提取 __VA_ARGS__? 2022-01-01