C++字符串处理小技巧总结

字符串反转:

string s;
reverse(s.begin(),s.end());

单个数字转字符:

string s="";
    int n=9;
    s+=(n+'0');
    cout<<s<<endl;

单个字符转数字:

char c='9';
int n=c-'0';
cout<<c<<endl;

字符串拼接:

#include<bits/stdc++.h>
using namespace std;
int main(){

    string s="";    //法一
    string st="abcd";
    s+=st;
    string ss;  //法二
    ss+=st;
    cout<<s<<endl;
    cout<<ss<<endl;
    return 0;
}

 字符串剪切:

s.erase(s.begin());

(常用于去除前导零)

原文地址:https://www.cnblogs.com/dreamzj/p/15000120.html