Quick & dirty into CPP

Quick and dirty into C++

  • Example code (without header file):
    Line Source code Result
    // 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:
    1. 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 */
    2. 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.
    3. All the elements of the standard C++ library are declared within what is called a namespace, the namespace with the name std.
    4. This is the short version of the main function where all C++ programs start their execution.
    5. cout << represents the standard output stream in C++.
    6. Return to OS without any errors during its execution. Returning a NOT 0 integer means that something went wrong in the program.
    7. { } braces for program codes scope isolation.
© 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.