C++ cctype ispunct() Function
Example
Check if a character is a punctuation character:
char c = '!';
if (ispunct(c)) {
cout << c << " is a punctuation character";
} else {
cout << c << " is not a punctuation character";
}
Definition and Usage
The ispunct() function checks if a character is a punctuation character.
Punctuation characters are all printable characters that are not letters, digits or spaces, like !, ?, # and @. It returns a non-zero number (true) if it is, and 0 (false) if it is not.
The ispunct function is defined in the <cctype> header file.
Syntax
int ispunct(int c);
Parameter Values
| Parameter | Description |
|---|---|
| c | Required. The character to check. |
Technical Details
| Returns: | An int value. Non-zero (true) if the character is a punctuation character, otherwise 0 (false). |
|---|
Related Pages
Read more about strings in our Strings Tutorial.