0

How do I detect certain words on one line

Kinda like a keyword system. I'm using getline(cin, x , '\n') and I'm kerfuffled. Say I wanted to detect 'cat' and 'dog'. So, if you typed "cat: Maine Coon dog: Pug", it would output Maine Coon and Pug. How would I do that?

5th Dec 2017, 5:42 PM
thebbcismymain
2 Respuestas
+ 1
Check out this as well. It's pretty common to parse strings with Regular Expressions, or regex: http://www.cplusplus.com/reference/regex/
5th Dec 2017, 11:44 PM
Zeke Williams
Zeke Williams - avatar
- 1
I've got an example in this code (getInput function near bottom of the code). https://code.sololearn.com/cMMmkTfOxOoR/?ref=app I used a state machine to know what I was processing, since I had a fixed pattern.
5th Dec 2017, 6:23 PM
John Wells
John Wells - avatar