Quick & dirty into CPP
Quick and dirty into C++
-
Example code (without header file):
Line Source code Result 1 2 3 4 5 6 7
// my first program in C++ #include <iostream> using namespace std; int main () { cout << "Hello World!\n"; return 0; }
Hello World!
You can download this example here (needed tools can be found in the right menu on this page).
-
In contrast to Java, a C++ requires only one function to be a program.
With reference to each line:
-
This line is a comment and C++ two types of comments:
// The rest of this line is a comment /* This is a comment the can be written over several lines */
- Includes the declarations of the standard input-output function and class library, <iostreams>, in C++ and start with #include verb. The preprocessor executes this before any program compiling.
- All the elements of the standard C++ library are declared within what is called a namespace, the namespace with the name std.
- This is the short version of the main function where all C++ programs start their execution.
- cout << represents the standard output stream in C++.
- Return to OS without any errors during its execution. Returning a NOT 0 integer means that something went wrong in the program.
- { } braces for program codes scope isolation.
-
This line is a comment and C++ two types of comments:
© 2010 by Finnesand Data.
All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the
correctness in the pages or source codes.
The risk of using this web-site pages or any program
codes from this website is entirely at the individual user.