7.1 Handling Input


7.1 Handling Input

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.




Introduction to Game Programming with C++
Introduction to Game Programming with C++ (Wordware Game Developers Library)
ISBN: 1598220322
EAN: 2147483647
Year: 2007
Pages: 225
Authors: Alan Thorn

Similar book on Amazon
Beginning C++ Through Game Programming
Beginning C++ Through Game Programming
Beginning Game Programming
Beginning Game Programming
The Ultimate Guide to Video Game Writing and Design
The Ultimate Guide to Video Game Writing and Design

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net