USER INPUTS IN C++

SAIROSHNI

 


User Inputs

  • Generally ,Cout is used to output values.
  • Here,cin to get user input.
  • cin is a predefined variable that reads data from the keyboard with the extraction operator(>>).

Program:

#include <iostream>
int main() {
    int user_input;
    std::cout << "Enter a number: ";
    std::cin >> user_input;
    std::cout << "You entered: " << user_input << std::endl;
    return 0;
}

Output:

Enter a number: [user enters a number, e.g. 42]
You entered: 42






Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send