C++ Tutorials (for beginners and cheapskates) 5
th
May 2004By Bob Jacobs
3
Before You Start
Conventions, compiler issues and the ISO Standard
1. Introduction
This section describes the conventions adopted in the tutorials that follow. Please read this sectionbefore you begin any of the tutorials. If the issues described below don’t mean anything to you thenyou probably need to start with the First C++ Program tutorial.Wherever possible the tutorials reflect the ISO C++ Standard. The example code should be portablebetween platforms if you’re using a relatively up-to-date compiler.
2. Header files
All of the examples in the tutorials use the header files from the ISO C++ Standard. In other words Iuse, for example:<iostream> and <vector> rather than the older <iostream.h> or <vector.h>also:<cstdio> and <cstdlib> rather than the deprecated <stdio.h> and <stdlib.h>If you’re not used to using the standard headers in your code now would be a good time to start. If your C++ book uses the older headers consider buying a more up-to-date book. If you don’t yet own abook keep this in mind when you choose one. If your compiler doesn’t have the new headers consider upgrading your compiler. If your professor, lecturer or tutor teaches you to use the older headers makea formal complaint and ask for your money back.If you still prefer to use the older headers go right ahead. Just be aware that sometimes your programmay exhibit slightly different behaviour to that described.
3. Namespace std
All of my code examples qualify the use of entities from namespace std with a using directive:using namespace std;This is done for convenience to keep the body of the code clear so that the reader can focus on thesubject being described. Refer also to First C++ Program, section 7, for further discussion of namespace std.
4. Returning from main()
The return statement in function main() is optional (it defaults to return 0). Some people prefer toinclude it; I omit it in my code examples unless I return something other than 0, or I have multiplereturns from main(). Refer also to First C++ Program, section 5, for further discussion of returning frommain().If your compiler won’t accept main() without a return statement, and some older compilers won’t, byall means add one.
Leave a Comment