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:
#include <iostream>
: Includes the input-output stream header file that allows input and output operations.int main() { }
: Defines the main function where the execution of the program begins.int number;
: Declares an integer variable namednumber
to store the user input.std::cout << "Enter a number: ";
: Displays the message "Enter a number: " on the console to prompt the user for input.std::cin >> number;
: Takes user input from the console and stores it in the variablenumber
.std::cout << "You entered: " << number << std::endl;
: Prints the message "You entered: " along with the value stored in thenumber
variable on the console.return 0;
: Indicates the successful execution of the program by returning 0 to the operating system.