Most programs require input from a user. Users might be expected to enter their name, age, or address. In a word processing application, for example, a user is expected to press keys on the keyboard to assemble a document and use the mouse to click on buttons and access various options. These are all forms of user input. This section examines only briefly how some keyboard input can be given, and reserves a more detailed examination of input later, as detailed game programming is considered. Consider the following sample C++ program.
#include <iostream> int main() { int Age = 0; std::cout<<"Please Enter Age\n"; //Prints text std::cin >> Age; //Accepts entered text, then press Enter std::cout<<"Your age is "<<Age; //Print text and age return 0; }
Note | The above code uses cin, which is like cout. The cout function prints text on the screen while cin requires text to be input, and the >> symbol indicates the entered value is to be stored in the Age variable. |