Computer >> 컴퓨터 >  >> 프로그램 작성 >> C++

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