使用迭代器输出vector中的内容

#include "iostream"
#include "string"
#include "cctype"
#include "vector"

using namespace std;

int main(){
    vector str;
    string t;
    //结束输入需要Ctrl+Z
    while (cin >> t) {
        str.push_back(t);

    }

    //第一遍循环迭代全体字符串
    for (auto it = str.begin(); it != str.end(); ++it){
            
            //第二遍循环迭代字符串里的字符
            for (auto it2 = it->begin(); it2 != it->end(); ++it2){
                
                //toupper()的参数是字符  而不是字符串
                *it2 = toupper(*it2);
                cout << *it2 << ' ';
            }
    }

    cout << endl;
    return 0;
}

原文地址:https://www.cnblogs.com/wuOverflow/p/4098767.html