字符串的一些常用函数(长更)

reverse()

字符串翻转

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    string s= "hello";
    reverse(s.begin(),s.end());
    cout << s << endl;
    return 0;
}

输出:olleh

strcmp()

在 algorithm 中;
从左到右,依次比较字母的ASCII码的大小,遇到不同字符或'\0'结束。
基本形式:strcmp(str1,str2)
str1=str2时,返回零;str1<str2时,返回负数;str1>str2时,返回正数。

posted on 2020-10-03 15:30  aiyi0325  阅读(61)  评论(0)    收藏  举报

导航