In the word of object-oriented programming, we "encapsulate" data and methods used to access/manipulate that data into one
class
or object.
In this case,
input
is a string which contains not only specific characters (the data), but also several methods to help us with the data. You access those methods with functions after the
.
.
Here is a list of all methods defined by the
string
class:
http://www.cplusplus.com/reference/string/string/
.size() returns the number of characters in the string. That's defined here:
http://www.cplusplus.com/reference/string/string/size/
You also have things like:
.find('a');
which will find the position of the first 'a' in the string.
Even the [] operator you use in
input[i]
is a method which specifies which character to return. That's defined here:
http://www.cplusplus.com/reference/string/string/operator%5B%5D/
Actually, your definition of output is called a "constructor". The
string
class has defined what that first parameter (int n) and that second parameter (char c) are used for in the construction of output. That's defined here (as constructor #6):
http://www.cplusplus.com/reference/string/string/string/
Without the encapsulation, you'd have to manipulate everything on your own. After working with string, I can't stand the tediousness of using character arrays anymore.