- Install Microsoft Visual Studio
- Create a Project with Microsoft
- Writing a Program in Microsoft Visual Studio
- Running a Program in Visual Studio
- Compatibility Issue #1: stdafx.h
- Compatibility Issue #2: Pausing the Screen
- If You're Not Using Microsoft
- Advancing to the Next Print Line
- Storing Data: C++ Variables
- Introduction to Data Types
- A Word about Variable Names and Keywords
- Chapter 1 Summary
Compatibility Issue #2: Pausing the Screen
As stated earlier, if you build and run the program by pressing Ctrl+F5, your results should be satisfactory, but if you press F5, you’ll get the problem of the program output flashing on the screen and disappearing.
If you’re using Microsoft Visual Studio, the easiest solution is to just press Ctrl+F5 (Start Without Debugging) every time you build and run the program. However, not all compilers offer this option.
Another way to deal with the problem of output flashing on the screen and disappearing is to add the following line of code, just above “return 0;”:
When this statement is executed, it has roughly the same effect as pressing Ctrl+F5. It causes the program to pause and print “Press any key to continue.”
The problem with this statement is that it is system specific. It does what you want in Windows, but it might not work on another platform. Only put this statement in if you’re reasonably sure you want your program to run just on Windows-based systems.
If you’re working on another platform, you’ll need to look for another solution. Check your compiler documentation for more information.
Now, if you’re using Microsoft Visual Studio, skip ahead to Exercise 1.1.