tutorialcup@gmail.com

C++ Environment Setup

 

Where to write a C++ program

The first thing you have to do once you start learning C++ is downloading and installing Integrated Development Environment (IDE). For this purpose Visual Studio 2013 is a good choice. It's free to download and it provides large possibilities for C++ Developer.

Download Visual Studio

You can download Visual Studio 2013 Express from the official Microsoft site below.

Download: "Express 2013 for Windows Desktop" from below link

Download Link: https://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx

On clicking download link you will see the page as shown below


download-visual-studio-express.png

After this download and install wdexpress_full.exe to install Visual Studio. 

After this you have to press "NEXT". The download will start automatically. When the file is downloaded you have to open it. After this follow simple installation and install the Visual Studio 2013.

If you have any problems while installing Visual Studio 2013 you can try to install any older versions of the Visual Studio. You can find older versions of Visual Studio here:http://www.visualstudio.com/downloads/download-visual-studio-vs

Once you have installed the Visual Studio you can open it and we will create the first C++ program. Once you open the Visual Studio you will see the Start Page:

Open a new project in visual studio

Create C++ Project

To create a C++ Project press File from menu and select "New project". After this project wizard will be opened. In this wizard select Installed -> Templates -> Visual C++ -> Win32 console application as is show on this picture:

Open a new project in visual studio

Type "HelloWorld" in the Name field and click "OK" button. After this a new window will appear. Now you have to click "next" button:

Open a new project in visual studio

In the next window you have to check only "Empty project" options. Your settings should look in this way:

Open a new project in visual studio

When you click finish – a project is created. We have to add a file to the HelloWorld project. For this purpose, right click on the project name in solution explorer is show in this picture:

Open a new project in visual studio

Here you have to select Add-> New Item. A new window will appear. By default you will be able to create C++ file with extension .cpp. You have to specify just the name of the new file. We will name this file HelloWorld:

Open a new project in visual studio

Now in Solution Explorer New source file appears. Double click on this file to open it. The file is empty and now we will create the first program by adding these simple file of code:

Try It

//include a header file from  Standard Library
#include <iostream>
using namespace std;
//the work of the program starts  from function called main
int main()
{
	//use standard(console) to output  message "Hello World"
	cout << "Hello world" << endl;
	//wait for user to press a key
	cin.ignore();
	//return a value to the system  when program finish its execution successfully
	return 0;
}

Now you can run your program by pressing "Local Windows Debugger" or using shortcut key "F5":

Open a new project in visual studio

If a dialog appears – press Yes button for building your application. Once your application is built – a command line window will be opened and you will see your application working:

run a program in visual studio

Now let's understand what does these few lines of codes do. The first thing that you have to know is that all the lines that start with "//" characters are comments and they are ignored by the compiler. They are used to comment anything about code so as to make you program understandable to any other programmers.

As you know, one part of C++ is Standard Library which provides a large number of different useful functions and objects. To use some of these capabilities we have to include a header file called iostream:

#include 

Now we will ignore the next line, because namespaces will be discussed in later articles. Just now you have to know that you have to include below line in your program to be able to use objects from iostream:

using namespace std;

The execution of the program starts with "main()" function:

int main()

Now we can write the body of the program. The goal is to show a "Hello world" message in the console. The object, called "cout" is used for output of the data into the console. The operator "<<" is used to specify what should be displayed. We want to display a string, Strings are specified within double quotes (" "). Strings will be discussed more details later. The last object to be displayed is endl which is used as new line character.

//use standard(console) to output message "Hello  World"
cout << "Hello world" << endl;

If we run the program by pressing Ctrl+F5 button, then the console window will close immediately. Now we want to keep the output window open after displayig the message. For this purpose we are waiting for user to press any key. It's done by the following line of code:

//wait for user to press a key
cin.ignore();

If the program terminates successfully – it will return a value to the system:

//return a value to the system when program finish its  execution successfully
return 0;

This is a basic C++ program. But if you follow this tutorial carefully – you will be able to write much more complex programs.

C++ Interview Questions


Next > < Prev
Scroll to Top