scan input c++

#include <iostream>

int main() {
    int number;

    std::cout << "Enter a number: ";
    std::cin >> number;

    std::cout << "You entered: " << number << std::endl;

    return 0;
}

Explanation:

  1. #include <iostream>: Includes the input-output stream header file that allows input and output operations.

  2. int main() { }: Defines the main function where the execution of the program begins.

  3. int number;: Declares an integer variable named number to store the user input.

  4. std::cout << "Enter a number: ";: Displays the message "Enter a number: " on the console to prompt the user for input.

  5. std::cin >> number;: Takes user input from the console and stores it in the variable number.

  6. std::cout << "You entered: " << number << std::endl;: Prints the message "You entered: " along with the value stored in the number variable on the console.

  7. return 0;: Indicates the successful execution of the program by returning 0 to the operating system.