CPP
C++ is a compiled low-level programming language. It is an enhancement of the language C.
The name 'C++' comes from the increment operator in C, which is "++" therefore C++
Because C++ is a compiled language, you will need a compiler to compile your code. Most Linux distributions come with the proper tools such as gcc, and gdb installed. If you do not have these installed, you can install through your respective package manager.
Debian/Ubuntu: apt get build-essential
Arch Linux: pacman -S base-devel
Hello World
Here is a quick example of a "Hello World" application in C++, and how to compile it.
The code
#include <iostream> //preprocessor directive, tells the compiler to 'include' the file "iostream" //This is a comment by the way. /* so is this. except it's a multi-line comment. */ //The compiler ignores comments. //here is our "main" function. int main(int argc, char *argv[]) //argc and argv stand for "Argument Count" and "Argument Vector" { std::cout << "Hello World!" << std::endl; //use cout to print the text "Hello World!" to the console. return 0; //return 0 and exit. } |
Compiling the Hello World
Assuming you have GCC installed, Save the previous code as "helloworld.cpp". In the same directory that you saved your source file, open a terminal and type the following:
gcc helloworld.cpp -o helloworld
Now GCC has compiled your source code into an executable file.
execute your hello world application with:
./helloworld