Now, for starters, I will be illustrating how to code in C++ using xcode. If you are using windows, you can download visual studio from Microsoft website. It is a really good software for programming in C++ and my brother who is study a degree in real time interactive programming gives quite a good review on it. Here is the link. Please do let me know in the event that the link is not working so that I can keep my page updated.
In short, C++ is a language you will eventually have to learn if you are planning on building your own games. Of course, the language also can be used to build other software applications apart from game. Just a short disclaimer: I am not a professional programmer and I am still learning like many of you do. If you have question, please feel free to pop me a comment. I will reply to the best of my ability. I believe that this will help me learn as well.
So let's get started. This tutorial will simply be a simple program that prints out the string 'Hello world!'. Yes, for those of you who are using xcode may realise that it is the default program once you create you new application. If you are using xcode to create a new C++ program, select 'New Project'.
You will see the following screen where you will be able to choose what type of application or program you would like to create. For starters, we will be working on OS X application command line tool to learnt the basic. We may venture to the rest in time to come. So hit 'Next' once you have selected 'Command Line Tool' under OS X Application
Hope you are still with me. After hitting next, you will be asked to type in your product name, organisation name and organisation identifier. You can type in anything that suits you, perhaps a name or some alphabet will do as we will be using this project as a practice before creating an official program.
Since we will be writing a program that prints out Hello World!, we can just put that as our program name. After that hit 'Next' button, the program will prompt you to save your project somewhere. So save it in a folder which is easy for you to access. After that, in the landing page, you will see something like this:
If you have selected main.cpp, you will see the code appearing on the right hand side. Yes, you do not have to type any thing, this code can actually print out "Hello, World!". To run the code, simply press "command" + "r" on your keyboard.
Viola! Your first Hello, World! program is done.
As simple as that, you have your first program that prints out Hello, World! Well, now we are interested to know which line in the program actually gives us the command to print "Hello, World!". Can you make a guess?
Even if you had not programmed before, we will try to look for the sentence which contains the string that had been printed:
std::cout << "Hello, World!\n";
So it seems that the above line will print out Hello, World! for us. Let's experiment if our guess is correct or wrong. So try typing in a similar sentence structure below:
std::cout << "Experimenting our guess~\n";
Do remember to key it in exactly, as mistypes may result in errors in your program. Have you done it? Are our codes look exactly the same? Ready to try?
Same step: Let is press "command" + "r" again to run our program.
Hoho! Seems like we are right after all. See programming can be simple as most of the things are logical. We just need to be clear on our commands (step-by-step) instruction for the computers to follow and achieve the ideal results that we want to create.
Well, that's all for this tutorial. Meanwhile, you may like to explore different things yourself as this is only one of the many methods for us to print strings in C++. You can look up the net as different people may have their own ways of doing this. I will be posting up a second tutorial in time to come. So do look out for it.
Have a good weekend. Enjoy your June holidays if you are still a students. :)
No comments:
Post a Comment