最近在学习C++的string和vector类,现在对这两样的使用比较模糊,我不太明白在toupper那里为什么要有两层的范围for循环,不能理解两个for循环是在干嘛
#include
#include
#include
#include
using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;
int main()
{
vector v;
string s;
while (cin >> s)
{
v.push_back(s);
}
for (auto& str : v)
{
for (auto& c : str)
{
c = toupper(c);
}
}
for (auto i : v)
{
cout << i << endl;
}
return 0;
}
希望得到解答,谢谢!原题如配图所示

因为vector中存储的是字符串,而字符串是字符数组,双循环是需要对字符进行大小写转换
第一层循环遍历vector中的每个字符串str
第二层循环遍历字符串str中的每个字符c
然后toupper对c字符进行大写字符转换