From 0fb13d805d2604898e6b14e82eb0f1cffa6a752c Mon Sep 17 00:00:00 2001 From: Vicky Nguyen Date: Wed, 6 Sep 2023 13:57:42 -0700 Subject: [PATCH 1/2] first paragraph only, change range for to iterator --- ch03/ex3_22.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ch03/ex3_22.cpp b/ch03/ex3_22.cpp index ce289a738..1fbe77e73 100644 --- a/ch03/ex3_22.cpp +++ b/ch03/ex3_22.cpp @@ -14,15 +14,14 @@ using std::vector; using std::string; using std::cout; using std::cin; using std int main() { - vector text; - for (string line; getline(cin, line); text.push_back(line)); + string text; + getline(cin, text); - for (auto& word : text) + for (auto it = text.begin(); it != text.end(); ++it) { - for (auto& ch : word) - if (isalpha(ch)) ch = toupper(ch); - cout << word << " "; + if (isalpha(*it)) *it = toupper(*it); } + cout << text << '\n'; return 0; } From 92564d0b7463dd2c4878174f3a8c5f755f41c400 Mon Sep 17 00:00:00 2001 From: Vicky Nguyen Date: Wed, 6 Sep 2023 14:11:33 -0700 Subject: [PATCH 2/2] remove vector --- ch03/ex3_22.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ch03/ex3_22.cpp b/ch03/ex3_22.cpp index 1fbe77e73..0322bb6d9 100644 --- a/ch03/ex3_22.cpp +++ b/ch03/ex3_22.cpp @@ -6,11 +6,10 @@ // #include -#include #include #include -using std::vector; using std::string; using std::cout; using std::cin; using std::isalpha; +using std::string; using std::cout; using std::cin; using std::isalpha; int main() {