I am trying something different with cin.get()
like given below:
char chArray[30]="character array with size "; //current string size is 25 character with null character
cout<< chArray << sizeof(chArray)<< endl;
cout<< "Now we will try to enter more than 30 character in chArray using cin.get()";
cin.get(chArray,100);
cout<< chArray << endl << sizeof(chArray)<< endl;
output of above code is very strange as given below:
character array with size 30
Now we will try to enter more than 30 character in chArray
using cin.get()
.
The character array size is 30 but we are entering more than 30 using cin.get()
but the size is still 30.
How is size of chArray
not changing from 30 to the size of the string we entered using cin.get()
?
Please explain.
std::string
, on the other hand will change size when used with the correct functions.