字符串

字符串拷贝

string a = "a";
string b = a; //b是a字符串的拷贝,是副本
cout<<a<<"-"<<b<<endl; // a-a
b = "b";
cout<<a<<"-"<<b<<endl; // a-b

字符串中字符排序

sort(s.begin(),s.end(),cmp);

字符串长度对齐

右对齐

如:4位对齐,输入1,要求得到"0001";输入11,要求得到"0011"
s.insert(0,4-s.length,'0');

左对齐

如:4位对齐,输入1,要求得到"1000",输入11,要求得到"1100"
s.insert(s.length,4-s.length,'0');

字符串反转

#include <algorithm>
reverse(ds.begin(),ds.end());
posted @ 2020-02-04 14:36  JamieHou  阅读(85)  评论(0编辑  收藏  举报