You need to include null terminators at the end of each of your character arrays.
For example,
char myyear[5] = { dob[0], dob[1], dob[2], dob[3], 0 };
cout
(along with many other string-type functions in C and C++) requires a string to be modelled as a sequence of characters terminated by a 0.
What you are doing at the moment is, technically, undefined behaviour: the fact that you are getting any output at all is to be considered entierly coincidental.
By the way, why are you modelling the numeric values like this? std::cout
also works for integer types: e.g. int myyear = 1981; cout << myyear;
is perfectly valid.