这里主要就是涉及到了一个 string 的大小写转换函数 (在 algorithm 的库里):
transform(first, last, result, op);
first 是容器的首迭代器, last 为容器的末迭代器, result 为存放结果的容器, op 为要进行操作的一元函数对象或 sturct,class.
具体使用如下:
- #include <iostream>
- #include <string>
- #include <cctype>
- #include <algorithm>
- using namespace std;
- int main()
- {
- string s = "Hello World";
- cout << s << endl;
- transform(s.begin(),s.end(),s.begin(),::toupper);// 变大写
- cout << s << endl;
- transform(s.begin(),s.end(),s.begin(),::tolower);// 变小写
- return 0;
- }
来源: http://www.bubuko.com/infodetail-3257463.html