C++ <cctype> - ispunct() Function
The C++ <cctype> ispunct() function is used to check if the given character is a punctuation character. In the default "C" locale, a punctuation character are all those graphic characters (as in isgraph) which are not alphanumeric (as in isalnum).
Other locales may consider a different selection of characters as punctuation characters.
Syntax
int ispunct ( int ch );
Parameters
ch |
Specify the character to be checked, casted to an int, or EOF. |
Return Value
Returns non-zero value (i.e, true) if ch is a punctuation character, else returns zero (i.e, false).
Example:
The example below shows the usage of ispunct() function.
#include <iostream> #include <cctype> using namespace std; int main (){ char str[50] = "Hello, World!"; //replacing all punctuation //characters with @ in str int i = 0; while(str[i]) { if(ispunct(str[i])) str[i] = '@'; i++; } //displaying the output cout<<"str contains: "<<str; return 0; }
The output of the above code will be:
str contains: Hello@ World@
❮ C++ <cctype> Library