close


最近因為刷起leetcode,所以用到了蠻大量的string這個類型,
用者用者才發現,其實自己還是有很多需要查詢的,
比如說這個string的大小寫切換,因為C++的string沒有自帶方法進行大小寫的轉換,
所以我們就必須透過一些方式來得到我們要的,而以下就是我所找到的方式,提供給大家參考。

 

 

 

image

 

#include <algorithm>
#include <string>


int main()
{
    string src = "hello world";
    string dst;
    transform(src.begin(), src.end(), back_inserter(dst), ::toupper);
    cout << dst << endl;


    dst = "";
    transform(src.begin(), src.end(), back_inserter(dst), ::tolower);
    cout << dst << endl;


    system("Pause");
    return 0;
}

 

 

arrow
arrow
    文章標籤
    string C++ C algorithm
    全站熱搜

    Eric 發表在 痞客邦 留言(0) 人氣()