how to get input in cpp

#include <iostream>

int main() {
    // Declare variable to store input
    int userInput;

    // Prompt the user for input
    std::cout << "Enter an integer: ";

    // Get input from the user
    std::cin >> userInput;

    // Display the input
    std::cout << "You entered: " << userInput << std::endl;

    // Return 0 to indicate successful completion
    return 0;
}