이 기사에서는 C++의 iswpunct() 함수, 구문, 작동 및 반환 값에 대해 설명합니다.
iswpunct() 함수는
구두 문자는 다음과 같습니다.
! @ # $ % ^ & * ( ) “ ‘ , . / ; [ { } ] : ? 구문
int iswpunct(wint_t ch);
이 함수는 하나의 매개변수, 즉 검사할 와이드 문자만 받습니다. 인수는 wint_t 또는 WEOF로 캐스트됩니다.
wint_t는 정수 유형의 데이터를 저장합니다.
반환 값
이 함수는 0(거짓인 경우) 또는 0이 아닌 값(참인 경우)이 될 수 있는 정수 값을 반환합니다.
예
#include <iostream>
#include <cwctype>
using namespace std;
int main() {
wint_t a = '.';
wint_t b = 'a';
wint_t c = '1';
iswpunct(a)?cout<<"\nIts Punctuation character":cout<<"\nNot Punctuation character";
iswpunct(b)?cout<<"\nIts Punctuation character":cout<<"\nNot Punctuation character";
iswpunct(c)?cout<<"\nIts Punctuation character":cout<<"\nNot Punctuation character";
} 출력
위의 코드를 실행하면 다음과 같은 출력이 생성됩니다 -
Its Punctuation character Not Punctuation character Not Punctuation character
예
#include <iostream>
#include <cwctype>
using namespace std;
int main () {
int i, count;
wchar_t s[] = L"@tutorials, point!!";
count = i = 0;
while (s[i]) {
if(iswpunct(s[i]))
count++;
i++;
}
cout<<"There are "<<count <<" punctuation characters.\n";
return 0;
} 출력
위의 코드를 실행하면 다음과 같은 출력이 생성됩니다 -
There are 4 punctuation characters.