Why my output will display this message? any wrong concept?

terminate called after throwing an instance of ‘std::out_of_range’
what(): basic_string::substr: __pos (which is 4) > this->size() (which is 3)

I’m only guessing but it looks like you’re calling substr with position 4 in a string of length 3. The index is out of range and the function throws.