Bleep.cpp freeform project help

In the references and pointers section in the c++ course, we’re instructed to create a program bleep.cpp. Here is the link to the lesson, and here is the solution.

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.

My solution is different from that you linked to, though the principles are the same.

For the bleep_it function, you can create a string of asterisks that matches the size of the word you want to bleep. That means getting the size of whatever word is sent, then creating your bleep word to match. Notice the solution you linked to did that.

Also notice that step 3 guides you to pass by reference so you can dynamically change the bleep word.

Then use text.find() and text.replace() to put your bleep into the bad word.

There once was a U.S. President who hated ********. It was nothing personal, but even his mother couldn’t get him to eat ******** as he was growing up. He liked baked beans, though. Still he wouldn’t eat ******** even if he could have baked beans too. I like ******** as long as it has enough basalmic vinegar on it. Then ******** tastes okay. The former President, though – he still doesn’t like ********.