In your example you don't need it to return anything, because the expression:
name.erase(0,1)
is equivalent to:
((void)name.erase(0,1), name)
So for example you could write:
while(name.erase(0,1).size()) {
std::cout << name << '\n';
}
or:
while((name.erase(0,1), name).size()) {
std::cout << name << '\n';
}
or:
while(name.erase(0,1), name.size()) {
std::cout << name << '\n';
}
or:
while(true) {
name.erase(0,1);
if (!name.size()) break;
std::cout << name << '\n';
}
The standard has decided to give you the choice, probably on the basis that it might as well use the return value for something rather than "waste" it.
Basically, it sometimes saves a little bit of code that repeats a variable name or takes a reference to an intermediate result.
Some people think that functions that modify the object they're called on should not return anything (the idea being to limit the use of functions with side-effects to one per statement). In C++ they just have to live with the fact that the designers of the standard library disagree.