string
宣告字串
string s="abcd";
字串反轉
string rs(s.rbegin(),s.rend()); //rs="dcba"
reverse(s.begin(),s.end()); //s="dcba"
將字串中一種字元全部替換掉成另一種
s="1,2,3,4";
//將字串s中的','全部轉成空白' '
replace(s.begin(),s.end(),',',' '); //<algorithm>
//s="1 2 3 4"
Last updated
Was this helpful?