how to take space separated input in c++

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

int main() {
    std::string input;
    std::getline(std::cin, input); // Read the entire line of input

    std::istringstream iss(input); // Create a string stream object with the input
    std::vector<std::string> tokens; // Create a vector to store the tokens

    std::string token;
    while (iss >> token) { // Extract space-separated tokens
        tokens.push_back(token); // Store each token in the vector
    }

    // Access and use the tokens as needed
    for (const auto& t : tokens) {
        std::cout << t << std::endl; // Output each token
    }

    return 0;
}