#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
    vector<string> x{"hello","world","ng"};
    //能在容器里面修改元素的方法
    //迭代器从x的begin也就是hello开始,每循环一次走下一个字符串
    //empty只能在这样的容器内使用
    //再定义一个引用,去范围遍历解引用i,也就是hello
    //最后再把引用的值改为大写,实际就是修改了hello
    for (auto i = x.begin();i != x.end() && !i->empty();++i) {
        for (auto& e : *i)
            e = toupper(e);
        cout << *i  << endl;
    }
    return 0;
}
最后修改:2022 年 12 月 05 日
如果觉得我的文章对你有用,请随意赞赏