å¨cctype头æ件ä¸æèªå¸¦çtoupper()åtolower()å½æ°ã
åªéè¦
12345678910#include <cstdio>#include <cctype>using namespace std; int main(){ char c1 = 'a', c2 = 'B'; printf("%c toupper = %c\n", c1, toupper(c1)); printf("%c tolower = %c\n", c2, tolower(c2)); return 0;}
è¾åºç»ææ¯ï¼
a toupper = A
B tolower = b
æè å¯ä»¥èªå·±å®ç°ä¸ä¸ªè¿æ ·çå½æ°ï¼
123456789int toupper(int ch){ if (ch < 'a' || ch > 'z') return -1; return ch - 'a' + 'A';} int tolower(int ch){ if (ch < 'A' || ch > 'Z') return -1; return ch - 'A' + 'a';}