char exchange(char c) { if (c <= 'Z' && c >= 'A') c = tolower(c); else if (c >= 'a' && c <= 'z') c = toupper(c); return c; } int main() { string strTmp = "short"; transform(strTmp.begin(), strTmp.end(), strTmp.begin(), ::toupper); //转换成大写 transform(strTmp.begin(), strTmp.end(), strTmp.begin(), ::tolower); //转换成小写 transform(strTmp.begin(), strTmp.end(), strTmp.begin(), exchange); //大小写互换 }