suibenzhi
4/15/2018 - 6:22 AM

c++大小写转换

c++大小写转换

#include <iostream> 
#include <string>
#include <algorithm>
#include <iterator>
#include <cctype>

using namespace std;

int main() 
{
    string src = "Hello World!";
    string dst;

    transform(src.begin(), src.end(), back_inserter(dst), ::toupper);//转换为大写
    cout << dst << endl;

    transform(src.begin(), src.end(), dst.begin(), ::tolower);//转换为小写
    cout << dst << endl;

    return 0;
 }