#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> text;
string s;
while(getline(cin, s))
text.push_back(s);
for(auto it = text.begin(); it != text.end() && !it->empty(); ++it)
{
for(auto it2 = it->begin(); it2 != it->end(); it2++)
{
*it2 = toupper(*it2);
cout << *it << endl;
}
}
return 0;
}
为什么不能写成 *it = toupper(*it);呢
*it是std::string类型,*it2是char类型
因为 * it2才是个字符类型啊,* it是string类型
这代码有问题,cout<< * it <<endl;应该放到内层循环外面
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> text;
string s;
while(getline(cin, s))
text.push_back(s);
for(auto it = text.begin(); it != text.end() && !it->empty(); ++it)
{
for(auto it2 = it->begin(); it2 != it->end(); it2++)
*it2 = toupper(*it2);
cout << *it << endl;
}
return 0;
}
*it是个string
toupper 要求一个char
*it2是个char