When trying to plan a way to handle this, I came up with first iterating through the text given with a for loop. The problem I’m having is that if you try to iterate through the given text, which is a std::string, you’ll get letters returned to you. This makes it difficult to compare with the banned word we’re given.
The only thing I can think of is to iterate through the std::string, and if characters “b”, “r”, “o”, “c”, “c”, “o”, “l”, “i” are produced in sequence, then replace them with “*”. But I don’t know the best way to accomplish that, and even if I did, I’m confident there’s a better way to go about this.
If the text were a vector, I’d iterate through that and then that’d return words, which I could then compare with the banned word “broccoli” and push_back() an asterisk or the word depending on whether or not they were equal, however it’s not a vector; it’s a string. Is there a way I can create a vector comprised of words from a string? If so, I’d then be able to iterate through it no problem.
I know formulating a plan is the first step before actually writing the code, so if anyone can look through what I’ve written here and address my questions and overall approach that’d be great. If you have a suggestion as to how you’d do this, I’d greatly appreciate your insight too. I wasn’t really able to deduce the plan from the provided solution.