C++ 字符串字母大小写转换
生活随笔
收集整理的這篇文章主要介紹了
C++ 字符串字母大小写转换
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
C++ 字符串字母大小寫轉(zhuǎn)換 使用algorithm,里面的tolower(轉(zhuǎn)小寫)toupper(轉(zhuǎn)大寫)
#include <iostream>
#include <string>
using namespace std;
#include <algorithm>int main()
{// 字符串大寫字母轉(zhuǎn)小寫string up_name = "ZHANG SAN";string to_low_name;transform(up_name.begin(), up_name.end(), back_inserter(to_low_name), ::tolower);cout << to_low_name << endl;// 字符串小寫字母轉(zhuǎn)大寫string low_name = "zhang san";string to_up_name;transform(low_name.begin(), low_name.end(), back_inserter(to_up_name), ::toupper);cout << to_up_name << endl;return 0;
}
總結(jié)
以上是生活随笔為你收集整理的C++ 字符串字母大小写转换的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 高考复读多少钱啊?
- 下一篇: C++ #define(宏定义)的使用