Avatar ·

How to iterate over words in a string in C++: analysis of popular methods

Hi everyone! I'm a beginner in C++ and I can't figure out how to properly split a string into individual words and loop through them. In Python, this is done in one line with `split()`, but in C++ everything seems complicated. I have a string like: `"Hello, how are you? I'm doing great!"` I need to output each word separately, ignoring punctuation marks and spaces. I tried using `std::stringstream`, but it doesn't remove commas and question marks — they stick to the words. For example, I get `"Hello,"` instead of `"Hello"`. I tried writing my own solution with manual space searching using `std::string::find`, but the code turns out huge and confusing. Moreover, my version doesn't work with tabs and multiple spaces. Please tell me how to do this correctly and elegantly? I'd like