From 9f44ed335a81a86e0812547c1f52b8145a375f8d Mon Sep 17 00:00:00 2001 From: Histo <30567433+samcw@users.noreply.github.com> Date: Tue, 11 Aug 2020 15:18:59 +0800 Subject: [PATCH] Update exercise9_43.cpp Change the condition, from `curr != s.end() - oldVal.size()` to `curr <= s.end() - oldVal.size()`. --- ch09/exercise9_43.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ch09/exercise9_43.cpp b/ch09/exercise9_43.cpp index 6d2e938..2405ea8 100644 --- a/ch09/exercise9_43.cpp +++ b/ch09/exercise9_43.cpp @@ -6,7 +6,7 @@ using namespace std; void replace(string& s, const string& oldVal, const string& newVal) { auto curr = s.begin(); - while (curr != s.end() - oldVal.size()) + while (curr <= s.end() - oldVal.size()) { if (oldVal == string(curr, curr + oldVal.size())) { @@ -28,4 +28,4 @@ int main() replace(s, "thru", "through"); cout << s; -} \ No newline at end of file +}