diff --git a/ch03/exercise3_22.cpp b/ch03/exercise3_22.cpp index e88faf3..3fe16a9 100644 --- a/ch03/exercise3_22.cpp +++ b/ch03/exercise3_22.cpp @@ -1,28 +1,23 @@ -#include +#修改之前那个输出text第一段的程序,首先把text的第一段全都改成大写形式,然后再输出它。 + #include -#include +#include #include +#include using namespace std; int main() { - vector text; - text.push_back("aaaaaaaaaa aaaaaaaaa aaaaaa"); - text.push_back(""); - text.push_back("bbbbbbbbbbbbbb bbbbbbbbbbb bbbbbbbbbbbbb"); - + vectortext; + text.push_back("aaa bbb ccc ddd eee fff"); for (auto it = text.begin(); it != text.end() && !it->empty(); ++it) { - for (auto &c : *it) - { - if (isalpha(c)) c = toupper(c); - } + for (auto it2 = it->begin(); !isspace(*it2); ++it2) + if (isalpha(*it2)) + *it2 = toupper(*it2); } - for (auto it : text) - { cout << it << endl; - } return 0; -} \ No newline at end of file +}