Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

C++ keyboard input

#include <iostream>  // for std::cout and std::cin
 
int main()
{
    std::cout << "Enter a number: "; // ask user for a number
 
    int x{ }; // define variable x to hold user input (and zero-initialize it)
    std::cin >> x; // get number from keyboard and store it in variable x
 
    std::cout << "You entered " << x << '
';
    return 0;
}

Enter a number: 4
You entered 4
Source by www.learncpp.com #
 
PREVIOUS NEXT
Tagged: #keyboard #input
ADD COMMENT
Topic
Name
8+1 =