// Code derived from Stroustrup's PPP2 book// § 11.6 Character classification// -and beginning on p 397#include<cctype>#include<iostream>usingnamespacestd;intmain(){// example input: 1 + 4 * x <= y / z * 5cout<<"\n> ";// exposition only:// note: this is an infinite loop; you'll need to break out of it yourself// -(ie, use ctrl+d to end input; see input stream comments on p 124)for(charch;cin.get(ch);){if(isspace(ch)){// if ch is whitespace;// nop; do nothing (i.e., skip whitespace)}if(isdigit(ch)){// read a number}elseif(isalpha(ch)){// read an identifier}else{// deal with operators}}}// exposition only:voidtest(charc){isspace(c);// is c whitespace? (' ', '\t', '\n', etc.)isalpha(c);// is c a letter? ('a'..'z', 'A'..'Z') note: not '_'isdigit(c);// is c a decimal digit? ('0'..'9')isxdigit(c);// is c hexadecimal digit: decimal digit or 'a'..'f' or 'A'..'F'isupper(c);// is c an upper-case letter?islower(c);// is c a lower-case letter?isalnum(c);// is c a letter or a decimal digit?iscntrl(c);// is c a control character (ACSII 0..31 and 127)ispunct(c);// is c not a letter, digit, whitespace, or invisible control// characterisprint(c);// is c printable (ASCIII ' '..'~')isgraph(c);// is c isalpha()|isdigit()|ispunct() (note, not space)toupper(c);// c or c's upper case equivalenttolower(c);// c or c's lower case equivalent}// put s into lower casevoidtolower(string&s){for(inti=0;i<(int)s.length();++i)s[i]=tolower(s[i]);}