C++ - User Input

In C++, user input can be obtained using the cin object from the iostream library. 

In this example, the program prompts the user to enter their age. The std::cout object is used to display the prompt message on the console. Then, the std::cin object is used to read the user's input, which is then stored in the age variable. Finally, the program displays the entered age using std::cout.

It's important to note that cin reads input until it encounters whitespace (such as spaces, tabs, or newlines). If you need to read an entire line of input, including spaces, you can use the getline function from the string library.

#include <iostream>
#include <string>	
int main() {
    std::string name;
    std::cout << "Enter your name: ";
    std::getline(std::cin, name);
    std::cout << "Your name is: " << name << std::endl;	
    return 0;
}

In this case, getline reads the entire line of input, including spaces, and stores it in the name variable.

Remember to include the necessary header files (iostream and string) at the beginning of your program to use cin and getline.

#include <iostream>	
int main() {
    int age;
    std::cout << "Enter your age: ";
    std::cin >> age;
    std::cout << "Your age is: " << age << std::endl;	
    return 0;
}