6.10 Outputting Results


6.10 Outputting Results

The examples demonstrated so far produce no visible output on the screen. The program begins, performs its instructions even though it might not appear so, and then terminates as though it never ran at all. The reader only has my word for it that these variables are actually being declared and manipulated. This section explains how the values of variables can be printed on screen for inspection. Consider the following sample C++ program:

      #include <iostream>      int main()      {         int Age = 27;         int Friend_Age = Age;         bool Is_Human = true;         float Pi = 3.14;         char Letter = 'a';         std::cout<<Friend_Age;         return 0;      } 
Note 

Variables can also be used as arguments, as we will see later when functions are considered more closely. Here the value of Friend_Age is printed using std::cout, in the same way text is printed.

Note 

For some IDEs, like Visual Studio, the program will often end immediately after execution. One way to solve this is to call a function that waits around for keyboard input. This way, the program ends when you press a key, like so:

      char Buffer;      std::cin >> Buffer; 




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