<C++ Primer_5th>习题_3.22

来源:互联网 发布:ubuntu修改hosts翻墙 编辑:程序博客网 时间:2024/05/17 00:03
//修改之前的那个输出 text第一段程序,首先把text的第一段全部改写成大写形式,然后再输出它#include<iostream>#include<string>#include<vector>using namespace std;int main(){vector<string> text;string s;cout << "请输入一段字符串" << endl;//利用getline读取一句话,直接回车产生一个空串,表示段落结束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;}system("pause");return 0;}

原创粉丝点击