从cin读入一组词存入Vector对象。然后把所有词转换为大写形式
- 知识点:向vector对象中添加元素,C11 for循环语句,topper函数使用将词改为大写
#include <iostream>
#include <vector>
#include <string>
int main()
{
std::vector<std::string> vString;
std::string s;
char count = 'y';
std::cout << "请输入一个词\n";
while (std::cin>>s)
{
vString.push_back(s);
std::cout << "还继续添加元素吗?\n";
std::cin>>count;
if (count != 'y' && count != 'Y')
{
break;
}
}
std::cout << "进行单词大写转换" << "\n";
for (auto &mem : vString)
{
for (auto &c : mem)
{
c = toupper(c);
}
std::cout << mem << std::endl;
}
return 0;
答案