计蒜客练习题:蒜头君学英语

   

这里主要就是涉及到了一个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; }

猜你喜欢

转载自www.cnblogs.com/Vikyanite/p/11740964.html