Hello world with C++

Here are the steps:

  1. Open Microsoft Visual Studio and create new project. If you copy-paste code directly into the program or open a pre-written .CPP (C++ ) file, it will not compile properly, therefore, it won’t run.
  2. Go to File -> New -> Project
  3. Then pick C++ from the main menu located in the window that pops up. A submenu will drop down; select WIN32 on the left hand side.
  4. Afterwards, select Win32 Console Application on the right hand side.
  5. Give it a name.
  6. Click OK.

  1. After the project is created Microsoft Visual Studio will ask you to configure the project.
  2. Click Next on the overview page to customize your project a little further.

  1. One the second screen, please select
  2. Console Application under Application type
  3. Empty Project under Additional options

Your project is now configured.

  1. After the project is done, you are ready to start programming.

/ Typically on the left hand side you will see The Solution Explorer. This is actually the file structure of your project. Microsoft Visual Studio creates 3 folders by default. Header files, Resource files, and Source files. Header files folder usually contains header file that you include into each file, created by the programmer. Resource files folder usually contains images or text files that I needed for the program. Source files folder contains the actual source code of the program. You will be creating your CPP files and they must be saved in Source files folder in order to run.
  1. To create new file right lick on Source files -> Add -> New item. A dialog window will pop up. Select C++ File (.cpp) option. Then give it a name and hit Add.

The file will be displayed in Source files folder and will be opened on the screen.

  1. Hello world program

#include <iostream>

int main()

{

std::cout < "Hello world\n";

return 0;

}

  1. Program should begin with including IOSTREAM library.

#include <iostream>

IOSTREAM library provides input – output functionality using strings. IOSTREAM is object-oriented library .

  1. Define MAIN function, data type must be INT

int main()

{

}

Int main() identifies where the operating system should start executing the program

c.  Print Hello world on the screen by using COUT command. Please note that since namespace has not been defined , a prefix STD should be used with following syntax

std::cout < "Hello world\n";

STD = standart

< - defines where complier should start executing COUT command

\n – inserts a new line

  1. Return proper INT value to the operating system

return 0;

(Comment: All the elements of the standard C++ library are declared within what is called a namespace, the namespace with the name std. http://www.cplusplus.com/doc/tutorial/program_structure.html)

  1. Verification. In order to test the program, please go to Debug -> Start without debugging or use Ctrl+F5. Your outcome should look like: