Professional Documents
Culture Documents
Objective
Demonstration of Visual studio 2020. Use of Program Editor, Compiler, linker & debugger
How to start
You can double click on the Visual Studio 2010 icon on the desktop. You can also click on the
startup menu at the left bottom corner on your window desktop, choose All Programs from the popup
menu, then choose Microsoft Visual Studio 2010, and then select Microsoft Visual Studio 2010 again.
To get started on your first program, you must create a "project" that will keep track of all the parts of
your program, including the C++ source code, the header files, etc.
To open a new project, you can use either of the following two methods:
1. Click on the File memu, select New, and then select Project.
OR
2. Click on the new project button in the following picture:
Select Project --> Add New Item... from the main menu, and select C++ File (.cpp) from the
"Templates" section in the middle section.
Type in the file name: "hello.cpp" in the Name: box.
Click on "Add".
This file will be added to the hello work space that we have just created, and a blank document will be
opened for editing. Please look at the following screen capture for you.
#include <iostream>
#include <string>
using namespace std;
int main()
{
char name[50];
cout << "Please enter your name" << endl;
cin >> name;
cout << "Hello, " << name << endl;
return 0;
}
1. It remembers all of the source code files that combine together to create one executable. In this
simple example, the file hello.cpp will be the only source file, but in larger applications you often
break the code up into several different files to make it easier to understand (and also to make it
possible for several people to work on it simultaneously). The project maintains a list of the
different source files and compiles all of them as necessary each time you want to create a new
executable.
2. It remembers compiler and linker options particular to this specific application. For example, it
remembers which libraries to link into the executable, whether or not you want to use pre-
compiled headers, and so on.
3. It remembers what type of project you wish to build: a console application, a windows
application, etc.
For now we will create a very simple project file and use it to compile hello.cpp.
Multi-line Comment: begins with /* and ends with */. It may span more than one lines
End-of-line Comment: begins with // and lasts until the end of the current line
#include <iostream>
using namespace std;
The "#include" is called a preprocessor directive. Preprocessor directives begin with a # sign.
They are processed before compilation. The directive "#include <iostream>" tells the
preprocessor to include the "iostream" header file to support input/output operations. The "using
namespace std;" statement declares std as the default namespace used in this program. The
names cout and endl, which is used in this program, belong to the std namespace. These two
lines shall be present in all our programs. I will explain their meaning later.
int main()
{
statement 1;
statement 2;
return 0;
}
defines the so-called main() function. The main() function is the entry point of program
execution. main() is required to return an int (integer).
"cout" refers to the standard output (or Console OUTput). The symbol << is called the stream
insertion operator (or put-to operator), which is used to put the string "hello, world" to the
console. "endl" denotes the END-of-Line or newline, which is put to the console to bring the
cursor to the beginning of the next line.
return 0;
terminates the main() function and returns a value of 0 to the operating system. Typically, return
value of 0 signals normal termination; whereas value of non-zero (usually 1) signals abnormal
termination. This line is optional. C++ compiler will implicitly insert a "return 0;" to the end of
the main() function.
Task:
Create a Project , add CPP file in the source folder and then write a simple program to display
WELCOME TO FOP LAB message. Build and run this project.