vector text;
string s = "hello world" ;
text.push_back(s);
for (auto temp = text.begin(); temp != text.end() && temp->empty(); temp++)
{
for (auto temp2=(*temp).begin();temp2!=(*temp).end();temp2++)
*temp2 = toupper(*temp2);
}
for (auto it = text.cbegin(); it != text.cend() && !it->empty(); ++it)
cout << *it << endl;
或者是
for (auto temp = text.begin(); temp != text.end() && !temp->empty(); temp++)
注意是:!temp->empty();
for (auto temp = text.begin(); temp != text.end() && temp->empty(); temp++)将其中的&& temp->empty()去掉便可;
因为你修改的是一个临时变量,并没有修改vector中真正的值,如果想修改需要写成引用的形式,将代码中的auto写成auto&