you need to allocate len_ + 1 chars ( new char[ len_ + 1 ]; ). +1 is for '\0' that indicates the end of the string