最近看到了一个用来转换字符大小写比较方便的函数。分享一下!
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
string s="abcedf";
transform(s.begin(), s.end(), s.begin(), toupper);//转换成大写
cout << s << endl;
transform(s.begin(), s.end(), s.begin(), tolower);//转换成小写
cout << s << endl;
}
transform函数原型
template < class InputIterator, class OutputIterator,
class UnaryOperator >
OutputIterator transform ( InputIterator first1, InputIterator last1,
OutputIterator result, UnaryOperator op );
template < class InputIterator1, class InputIterator2,
class OutputIterator, class BinaryOperator >
OutputIterator transform ( InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, OutputIterator result,
BinaryOperator binary_op );