C++ STL 中的 iswalpha() 函数


C++ STL 中的 iswalpha() 函数用于检查给定的宽字符是否为字母。

算法

Begin
   Initializes the strings.
   Call function iswalpha(str) to check whether it contains alphabet or not.
   If it contains alphabet, then value will be returned otherwise zero will be returned.
End

示例代码

#include <cwctype>
#include <iostream>
#include <cwchar>
#include <clocale>
using namespace std;
int main() {
   setlocale(LC_ALL, "ab1234");
   wchar_t s[] = L"a%$^^&)";
   bool flag = 0;
   for (int i=0; i<wcslen(s); i++) {
      if (iswalpha(s[i])) {
         flag = 1;
         break;
      }
   }
   if (flag)
      wcout << s << L" contains alphabets";
   else
      wcout << s << L" doesn't contain alphabets";
   return 0;
}

输出

a%$^^&) contains alphabets

更新于: 30-7-2019

95 浏览

开启你的 职业生涯

完成课程,获得认证

开始学习
广告
© . All rights reserved.