here’s what I need to do. I have a string in C++. For every line in the string, I need to append a few characters (like “>> “) to the beginning of the line. What I am struggling with is a good way to split the string around newlines, iterate through the elements appending the characters, and then rejoin the string together. I’ve seen a few ideas, such as strtok(), but I was hoping c++ strings would have something a little more elegant.
here’s what I need to do. I have a string in C++. For every
Share
Here’s a straight-forward solution. Maybe not the most efficient, but unless this is hot code or the string is huge, it should do fine. We suppose that your input string is called
input: