Javascript is fine for doing things in browser, which has obvious limitations. If you've done the java tutorial already, then you'll find that C++ and java are very similar (java descended from c++). So if java is similar to C++, why should we learn C++ and not just java? First of all, C++ is a different way of programming: oop isn't a requirement. Also, C++ is better for fine-tuning memory management, thus is geared for systems programming. It actually compiles (not to bytecode, but to machine code); for that reason, C++ is also faster than java. Finally, C++ (and C) have been around for quite a while, and many things are written in it. If you want to dig around in source code or join an open source project, just the great number of C++ projects in existance warrants learning how to read it, if only to find how to port it.
You'll need a compiler and an ide. In our experience, there are three ides and two compilers that are competitve and free:
For all of them, following the defaults in installation should be okay.
A compiler is a program that writes programs. So that copy of Word you use to bang out your reports? A compiler took the code the Microsoft programmers had pounded out and, interpreting it, coverted it to machine code and created an executable, or a program (Word). Since the code the compiler used was the _source_ of the program, it is called source code.
An Integrate Development Enviornment is always a better idea than just pounding your source into a text file, even though you should know how to do that too. Since an IDE takes care of common tasks for you (or should) and creates a project framework to help you get started and generate some boiler-plate code1, which can let you code more.
Well, let's get our feet wet with a trivial example. Open up your IDE, make a new project, and
code
#include <iostream.h>
int main(int argc, char *argv[]){ int count = 0; char food[10] = ""; cout<<"What would you like to eat today?\n"; cin>>food; cout<<"How many would you like to eat?"; cin>>count; if(count > 10) cout << "You fat greedy pig!"; else cout << "Wow, have you been dieting?"; return 0;}>
So let's parse this: the first two line are boilerplate, and intuitively make sense. We include the iostream (input-output stream) file (the .h type means a header file) and define a main. Unlike in js, functions in c++ are not marked by a function keyword, but merely have a return type, a name, an argument list, and the execution code in the following braces. Thus, the main (the only function the program will actually run: everything else will be run inside the main.) returns an integer, which the last line of the program does (return a 0)2. The main is appropriately named the main, and given two arguments. Don't worry about those: they're merely the number of command line arguments passed to the program, and the actual arguments themselves.
The next line is a wee bit more interesting. Now, we have type declarations, which are just like java's type declarations.
If you've been around the C world, you'll know that cout and cin don't exist for that world.