|
|
x.find(" ")
will return std::string::npos
when x
is "Bobby"
. std::string::npos
is the largest value that the return type of find
can hold. When you add one x.find(" ")+1
the value will overflow and become the smallest value, which is zero because the type is unsigned. So in the last iteration you are printing x.substr(0, 0);
(an empty string).