[Skip Navigation] [CSUSB] / [CNS] / [Comp Sci Dept] / [R J Botting] / [Samples] / c++.cctype
[Index] [Contents] [Source Text] [About] [Notation] [Copyright] [Comment/Contact] [Search ]
Tue Sep 18 15:25:08 PDT 2007

Contents


    C++ cctype library

      One of the oldest and most useful C++ libraries is the Character Type library inherited from ANSI C. You use these function to classify characters by their type and they work on even weird character sets like EBCDIC.

      On the other hand they don't work on strings or arrays of characters.

      Most of the functions test for particular types of characters, but two function change a characters case...

    1. For c:char. In the following list c stands for a char.

    2. isalnum(c)::bool=c is an alphanumeric character.
       	if( isalnum(c) ) ....
    3. isalpha(c)::bool=c is a letter.
       	while( isalpha(c) ) ....
    4. iscntrl(c)::bool=c is a special control character, ASCII(0)..ASCII(31).
       	bool remember_is_control = iscntrl(c);
    5. isdigit(c)::bool=c is a decimal digit, '0'..'9'.
    6. isgraph(c)::bool=c is a graphic character, a printing character other than space.
    7. islower(c)::bool=c is a lower case letter, 'a'..'z'.
    8. isprint(c)::bool=c is not a control character but prints something including a space.
    9. ispunct(c)::bool=c is a punctuation character = isprint(c) && !isspace(c) && !isalnum(c).
    10. isspace(c)::bool=c is a white space character including space, tab, newline, carriage return etc..
    11. isupper(c)::bool=c is an UPPER CASE LETTER.
    12. isxdigit(c)::bool=c is a hexadecimal digit, '0'..'9' | 'A'..'F' | 'a'..'f'.

    13. toupper(c)::char=converts lower case letters into upper case letters and copies all others.
       	char upper= toupper(c);
    14. tolower(c)::char=converts upper case letters into lower case letters and copies all others.
       	char lower= tolower(c);

    15. char::data_type=the 8 bit character set available on the computer in use.
    16. bool::data_type=data that is true or false and is used in conditions.

      Converting the case of strings

      The toupper and tolower functions apply only to characters not to strings. The don't have the best definitions to work with the <algorithm> library. Worse they are overloaded with versions in the <locale> library [ topic.asp?topic_id=228118 ] [ msg01286.html ] and so code like this [ toUpper.cpp ] is needed to use transform to change the case of a C++ string.

    . . . . . . . . . ( end of section C++ cctype library) <<Contents | End>>

End