string 转换成大写(或小写)

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);  //大小写互换
}

  

posted @ 2018-10-29 13:48  那一剑的風情  阅读(3430)  评论(0)    收藏  举报