how to split string into words c++

#include <iostream>
#include <sstream>
#include <vector>

int main() {
    std::string inputString;
    std::cout << "Enter a string: ";
    std::getline(std::cin, inputString);

    std::istringstream iss(inputString);
    std::vector<std::string> words;

    do {
        std::string word;
        iss >> word;
        if (!word.empty()) {
            words.push_back(word);
        }
    } while (iss);

    std::cout << "Words in the string:" << std::endl;
    for (const auto& word : words) {
        std::cout << word << std::endl;
    }

    return 0;
}