-
Exploding a string?
I have a program that takes in a line of input, separates it into individual words, and then runs each of those words through a method that replaces illegal characters (like ! and @) with spaces, and then inserts each word into a BST. For example, if a line of input was:
What would get broken up would be:
And then when the words went through my modify method, it would look like:
Notice however that "three four" is considered one word. What I need to do is break apart "three four" after the illegal characters are removed so that my word structure would now look like:
i.e. four nodes would be inserted, not three. Is there any way to do this?
-
Why don't you run the "replace illegal chars" before you split the words out?
--
Mats
-
A way you could replace characters is this (str being the string):
Code:
replace (str.begin(), str.end(), '@', ' ');