Popular Google Pages:
◕ Your Story ₹ 500/- Details..
◕ Bengali Story writing competition. Details..
◕ This article is regarding What is a Member Function in C++?
Last updated on: 12th December 2016.
◕ Let an example first.
using namespace std;
char state = 'T';
cout << "Displaying char constant using Member Function, cout.put(): " << endl;
The output of this program is:
Displaying char constant using Member Function, cout.put():
- Here cout.put() is a Member Function.
- A Member Function belongs to a class and it describes a method to manipulating the class data.
Here ostream class has a put() Member Function that is designed to output character constant such as 'T'.
Here put() is the class Member Function and cout is the class object.
- We can use a Member Function only with a particular object of that class. Here the cout is that object.
- To use a class Member Function with an object, we need a period (. full stop) to combine the object name with the function name.
This period is called the Membership Operator.
In this cout.put() Member Function we used a period sign as the membership operator.
- The cout.put() Member Function is an alternative of the << operator to display a character constant.
So why we need cout.put()?
- Because cout.put() was used in the old version of the C++ for displaying char constant such as 'A', 'B' etc.
◕ Bits & Bytes
◕ Integer Type in C++
◕ Rules for Variable Names
◕ Variable in C++
◕ Fundamental Data Types & Compound Data Types
Top of the page