Tony: What is C++?
Instructor: C++ is an Object orient programming which was developed by Bjarne Stroustrup by combining C and Simula67 programming languages in early 1980's.
And all this makes C++ a truly object oriented language.
Tony: How to write C+ programs?
Instructor: Let's start with a simple C++ program that print a string on the screen.
First of all open the Hello World program in your Eclipse IDE with a C++ project name as SimpleProgram. Delete the Hello world Program and type a new similar program.
/*============================================================================
Name : SimpleProgram.cpp
Author : RJ Chakraborty
Description : SimpleProgram in C++, Ansi-style
============================================================================*/
#include <iostream>
// include header file
using namespace std;
int main(){
cout<<"Learning C++\n"; // C++ Statement
return 0;
} // End of Example
It will be look like this which demonstrates some basic C++ features.
Program Explained
Basics
Output Operator
The iostream file
#include <iostream>
Namespace
Return Type of main()
int main(){
cout<<"Learning C++";
return 0;
}
In the next chapter we will be working with more complex C++ program with some more statements to learn.
Instructor: C++ is an Object orient programming which was developed by Bjarne Stroustrup by combining C and Simula67 programming languages in early 1980's.
- C+ is the superset of C. Hence both are somehow same upto a certain limit. Except this features which are added to C++ only:
- Inheritance,
- Function overloading
- Operator overloading
- Polymorphism
And all this makes C++ a truly object oriented language.
Tony: How to write C+ programs?
Instructor: Let's start with a simple C++ program that print a string on the screen.
First of all open the Hello World program in your Eclipse IDE with a C++ project name as SimpleProgram. Delete the Hello world Program and type a new similar program.
/*============================================================================
Name : SimpleProgram.cpp
Author : RJ Chakraborty
Description : SimpleProgram in C++, Ansi-style
============================================================================*/
#include <iostream>
// include header file
using namespace std;
int main(){
cout<<"Learning C++\n"; // C++ Statement
return 0;
} // End of Example
It will be look like this which demonstrates some basic C++ features.
Program Explained
Basics
- The above example contains only one function, main(). Every C+ program must have a main().
- C++ statements terminate with semicolons.
- Single line Comments start with double slash // and it will be terminated at the end of the line.
- For multi-line comments, C++ use /*,*/ symbols as like C.
Output Operator
cout<<"Learning C++\n";
- cout which pronounced as See-out is the print operator here which display the String in quotation along with a new line represented by \n.
- << is called the insertion or put to operator which inserts the contents of the variable on its right to the object on its left. Here object is cout.
The iostream file
#include <iostream>
- Here #include act as a preprocessor to add the content of the iostream file to the program. Earlier we use iostream.h as the header file to include. But ANSI C++ change that to iostream only.
- Iostream means input/output statements, thus every C++ program consist of input/output statements should include the iostream header file at the beginning of the program.
Namespace
using namespace std;
- New concept introduced by ANSI C++ standard committee.
- Here, std is the namespace where ANSI C++ standard class libraries are defined. This will bring all the identifiers defined in std to the current global scope.
Return Type of main()
int main(){
cout<<"Learning C++";
return 0;
}
- main() always returns an integer type value by default.
- Therefore, every main() in C++ should end with a return statement- return 0;
- Otherwise a warning or an error might occur.
- By default the return type for all functions in C++ is int.
In the next chapter we will be working with more complex C++ program with some more statements to learn.