Then search for each word in the dictionary and remove it from the string if found. We're saving it to our own std::string.
1 2 3 4 5 6 7 8 9 10 11 12
std::vector<std::string> Tokens;
// for each word in our dictionary...
for (std::vector<std::string>::iterator it = Dictionary.begin(); it != Dictionary.end(); ++it)
{
std::size_t found = MyLine.find(*it); // Search for the token
if (found != std::string::npos) // Was it found?
{
MyLine.erase(found, it->size()); // Take it out of our word
Tokens.push_back(*it); // Put it into a vector of words
}
}
JuanCamaney wrote:
I tried functions, classes.
This is funny. In effect you are saying, "I tried C++".
It's not clear what are the rules used.
Take this input string: "enter 123HDog and cat W346 edf gefh are good"
Broken into numeric and non-numeric parts, it would look like this:
1. "enter"
2. 123
3. "HDog and cat W"
4. 346
5. " edf gefh are good"
So the question at this stage is a clarification of the requirements please, how to determine which characters to put into the string.
What happened to "enter", "H", "W", " edf gefh "? On what basis are these characters or words discarded?
And please don't post the same question multiple times.