Getting Started with C++ Using Visual Studio 2015

Hello Everyone,
This is Saif from Karachi, enjoying rainy weather and writing this blog titled as ‘Getting Started with C++ Using Visual Studio 2015’ for you. This article is for beginners who want to get their journey started in programming world using C++.

After basic introduction to C++, this article will guide step by step how to write first program in C++ using Visual Studio 2015 as an IDE. Let’s Begin.

Basic Introduction of C++

C++ is a general-purpose, multi-paradigm, statically typed, hybrid programming language. It is an extension to C language adding ‘object-oriented’ features to its predecessor.  C++ program files have .cpp extension.

Applications

  • All major applications of adobe systems
  • Google
  • Mozilla
  • MySQL
  • Alias System – Autodesk Maya

IDEs  (Integrated Development Environments) Used for C++

  • Visual Studio
  • Eclipse
  • NetBeans
  • Code::Blocks
  • Dev C++
  • and Others

Getting Started with Visual Studio 2015

  1. Download and install Visual Studio 2015 from official website
  2. Open Visual Studio and create a new project.cp_vs_1
  3. Select visual C++ -> win32 -> Win32 Console Application and give a name to your First Project.cp_vs_3
  4. Complete win32 Application wizard by selecting nextcp_vs_4
  5. Check ‘Empty Project’ option and then click on finishcp_vs_5
  6. You will get something like thiscp_vs_6
  7. Solution Explorer is visible at top right side. Right click on ‘Source Files’ and add  a new itemcp_vs_7
  8. Select C++ File from the Options and Name your first program, then click ‘add’C++ File (.cpp)
  9. You will see that your first program file is open in an editor and also visible in Source Files directory. Here you will write the code for your first program.editor

Writing the First C++ Program

After installing IDE and creating out first project, it’s time to write our first C++ Program.

Before directly jumping into the code, let me introduce you with some c++ terms.

Header Files

Header files contains per-written standard functions and variables which are imported or used in a C++ program.

iostream: This header file is used for input and output services for C++ programs

Preprocessor Directives

They begin with the ‘#’ sign and used to include header files in a C++ program using ‘include’ key word. They tell the compiler to process these file before staring compilation process.

Standard Library (std)

Including standard library allows you to use function like cout, cin etc.
cout: This fuction is used to print something on the screen.
cin:   This function is used to take input from user.

Main Function

It is important to know that every C++ program always contain a ‘main‘ function and the program starts executing form this function.

int main(): ‘int’ indicates that when our program reaches the end of main function, it return an integer value to the operating system. Automatically a value of 0 is returned that indicates successful execution and termination of the program.

Terminator ( semicolon ) – The Important Thing

In C++ it is required to use semicolon (;) to terminate a statement. Forgetting semicolon will result in errors in your program.

Delimiter Brackets

Delimiter brackets ‘{}’ are use to indicate beginning and closing of a function or other code blocks like if, else, for, while etc.

Basic Program Structure

basic program structure

cin.get(): It is primarily used to get a line of text from user but in above program it is used to hold the screen. After you press any key, the program will be terminated. So, it is actually waiting for the user to enter some text. Alternative, System(“pause”) function can also be used for the same purpose which display this line of text at the end of program.
Press any key to continue . . .
‘endl’ or ‘\n’ : Both of them are used to give a line break (simply change the line)

basic program

After you write the above lines of code into your editor, press F5 or click ‘start debugging’ to execute the program.

debugging

When your Program is successfully executed, you will be able to see the following output on your screen.

output

Congratulations 🙂
We are done with setting up visual studio and successfully executing our first program.

Stay with Protorials for more tutorials.
Have a nice day!

Advertisements

1 thought on “Getting Started with C++ Using Visual Studio 2015”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s