This lesson 1 of the dummy guide represents a very basic start into the modern (old-school) world of C++. As is the case in practically all programming tutorials, the first lesson ought to have a Hello-World program example. I will stick to that principal here as well.
I won't explain every bit of example code, because I want you to focus primarily on the important code. I am not a teacher, I am a programmer. There are other individuals that are brilliant in explaining how C++ code works. I leave it to them to help you out. I recommend reading the book The C++ Programming Language, by Bjarne Stroustrup the creator of C++, if you need a deep-dive into the language. I consider that a brilliant choice. In my lessons I will try to not bore you, by focusing on the mere minimum that you need to know in order to get up to speed, and so we both stay motivated ;)
My C++ development environment of choice, Embarcadero's C++ Builder IDE (Integrated Development Environment) provides many aides and productivity features so that one can quickly feel comfortable with and get a good understanding of C++ code, as well as to get productive very quickly. I suggest you start writing code as soon as possible, build your program, run it, and see if you can figure out how the different pieces of code cooperates in order to achieve what the program in it meant to accomplish. Use the C++ Builder IDE to step through your code (F8 key), line by line. Don't forget to make use of the Code Insight (Ctrl + . ) feature, and of course the Help feature (F1 key) is always your buddy, especially when get stuck. For further guidance, I suggest you glance through the following technical paper: An Introduction to Embarcadero C++ Builder 2010, by Volker Hillman.
Okay, enough said. Let us get started here:
- Download and install Embarcadero's C++ Builder Starter edition (free), if you haven't already bought one of the more comprehensive C++ Builder Professional or C++ Builder Enterprise editions.
- Start a new Console Application project (menu options: File > New > Other > Console Application) and specify (inside the 'New Console Application' dialog box) options in line with: not using any of the available graphical frameworks, not using multi-threading, and not specifying any existing project source. After clicking on the OK button, the following code appears:
typedef char _TCHAR;
#define _tmain main
int _tmain(int argc, _TCHAR* argv)
Insert two lines of code inside the main function body, at the very beginning. Refer to the code in bold, here below:
int _tmain(int argc, _TCHAR* argv)
Press F9 so that the code will be compiled, linked and the program started up, automatically. Of course you ought to save the file and project, if you plan on keeping the program for future reference.
The first line of code puts the ("Hello, world!" text) string on screen, hence the function name put-s. The second line causes the program to wait on the user (you) to type a character. That way the console windows won't disappear immediately after displaying the 'Hello world!' text string, because it pauses there, waiting on keystrokes. As soon as you then type zero or more keystrokes and press enter, the program will commence quickly up to the end (returning value 0), and as a result the console window will disappear instantaneously.
Congratulations! :) You have written a working C++ program, made very easy and intuitive by C++ Builder. It is not a useful program by any means, but it is a start, and it will motivate you to progress!
Watch this space for lesson 2. Happy C++ coding! :)