how to convert n space separated integers in c++

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

int main() {
    std::string input;
    std::getline(std::cin, input);

    std::istringstream iss(input);
    std::vector<int> numbers;

    int num;
    while (iss >> num) {
        numbers.push_back(num);
    }

    // Access the converted integers in the 'numbers' vector
    for (int i : numbers) {
        // Process each integer as needed
    }

    return 0;
}