Step: Brief discussion:
In this example we used a string object to get user's input from
the keyboard, then serialized to initialized a character array.
Users can add a string of any size, but the application will
terminate if the length of the string contains more than 15
characters.
The c-string is an array of characters and can't be assigned to
one another, these must be copied to one another. When we store a c-string into an array, a null character is added
at the end of string. In contrast to c-string and arrays, a string object of C++
language can be assigned to each other. By nature, the string
objects are class type variables, and are designed to manipulate
chunks of characters.
c-string / Array C++ string object
--------------------------- ---------------------------
char ch1[10];char ch2[10] string str1; string str2;
strcpy(ch1, "Hello!"); str1 = "Hello";
strcpy(ch2, ch1); str2 = str1;
ch2=ch1;//not allowed
cin.getline(cstr1, sizecstr1+1); getline(cin, strobj);
The contents of the string objects are allocated with smaller
segments, thus preventing defragmentation of the heap structure.
All the above facts, are in favor of using string object to
receive users input from the keyboard, than using a character array.