Avatar ·

How to split a string into tokens (words) in C++? Detailed guide

Hello everyone! I just started learning C++ and encountered a problem that seems simple, but I can't find a normal solution. I need to split a string into individual words (tokens). For example, I have a string "Hello, world! This is C++". I want to get an array or vector: ["Hello,", "world!", "This", "is", "C++"]. In Python I would just write `"Hello, world! This is C++".split()` and it's done. But in C++ I don't see such a simple method. I know there is `std::string`, there is `std::stringstream`, but how do I extract individual words from them? I tried writing something like: ```cpp #include #include #include #include int main() { std::string str = "Hello, world! This is C++"; std::stringstream ss(str); std::string word