Course list http://www.c-jump.com/bcc/
The following C++ program will print text Hello, World! on computer screen:
#include <iostream> int main() { std::cout << "Hello, World!"; return 0; }
Our first program is constructed from the following parts...
#include <iostream>
int main()
{
std::cout << "Hello, World!";
return 0;
}
#include <iostream> is a directive to include keyboard and screen input/output functionality to our program. Without this directive, the program would have no means to print "Hello, World!" greeting on the screen.
#include <iostream>
int main()
{
std::cout << "Hello, World!";
return 0;
}
Second line contains main entry point into our program.
That is, when the program is loaded into memory, its execution begins here.
The word "main" is the name of a C++ function. C++ functions define computer operations. Entire combination int main() suggests two things:
main is a function with no input parameters, because parentheses are empty.
keyword int declares that main function returns an integer (number) back to the operating system.
Note: int and return are keywords (reserved words) of the C++ programming language.
#include <iostream> int main() { std::cout << "Hello, World!"; return 0; }
Opening brace "{" indicates beginning of our main function. Closing brace "}" ends the function. The braces specify function body.
Function body contains any programming code enclosed inside the braces.
#include <iostream>
int main()
{
std::cout << "Hello, World!";
return 0;
}
Statement std::cout << "Hello, World!"; sends quoted string of characters to console output device, namely cout.
Because cout is an object that comes from C++ standard library, it is prefixed by the namespace of the standard library, std::
Our program communicates with cout by using stream output operator << in order to print text on computer screen.
#include <iostream> int main() { std::cout << "Hello, World!"; return 0; }
Individual programming statements contain semicolon ";" at the end.
This is part of C++ syntax: individual statements must finish with semicolons.
Interestingly, semicolon is part of the statement itself, and is not a separator between multiple statements.
#include <iostream>
int main()
{
std::cout << "Hello, World!";
return 0;
}
The return 0; statement stops execution of the main function.
The return passes numeric value zero back to the caller of our program -- the operating system.
Zero indicates success.
Non-zero usually represents a well-known error code , signalling an unusual termination condition of the program (for example, "not enough memory," or "bad input parameters," etc.)
Microsoft Visual C++ Development environment includes an editor with program code colorization, syntax checking, on-line help, and other tools. It enables to find and diagnose programming errors using program debugger with graphical user interface.
Visual C++ allows writing portable, standards-conformant C++ programs that use advanced features of the language, based on concepts of object-oriented design and generic programming.
Combination of these qualities makes Microsoft Visual C++ an attractive choice for many novice programmers and professional developers. For developing highly portable code, it is crucial to compile your programs by as many different compilers as possible, and VC++ is certainly one of them.
Like many other graphical development environments, VC++ comes with its own terminology for configuration parameters associated with programming tasks.
To begin using Microsoft Visual C++ in our homework assignments, we need to create a new project in Microsoft development environment.
Essentially, project is a combination of configuration files, located in the project directory on the hard drive.
Each project is placed inside a solution, which allows loading multiple projects into the VC++ for parallel work.
When we create our first VC++ project, the solution is automatically created for us.
Open Microsoft Visual C++ development environment. From the top menu, select
File -> New -> Project...
When "New Project" dialog opens, specify the following parameters:
Name: main
Location: C:\CIS155
Uncheck "Create directory for solution" check box:
Next, click OK. Project Wizard dialog comes up:
Click Next
Select Win32 Console application project for the project type
IMPORTANT: uncheck Precompiled header check box option
IMPORTANT: check Empty project check box option
Click Finish:
In the "Solution Explorer" sidebar, right-click the "Source Files" and select
Add -> New Item...
The dilaog box opens:
Click "Visual C++" on the list of Categories on the left, click "C++ File (.cpp)" on the list of templates, type main.cpp in the Name box.
Click Add button.
File main.cpp opens as an empty source file in the editor window. Type text of the "Hello, World!" program:
#include <iostream> int main() { std::cout << "Hello, World!"; return 0; }
From the top menu, select
Build -> Build Solution
or simply hit the F7 key to compile the program. You should see the output window like this:
NOTE: If there are any errors, make sure you have created the project of the correct type and that you typed the program text exactly as shown above.
You should now be able to execute your program by combination of keys CTRL+F5.
The program should print "Hello, World!" greeting on the screen.