Suppose that we have a function:
void convert(std::istream& iss, std::ostream& oss)
{
std::string s;
// ...
// do something to feed s
// ...
oss << iss.rdbuf();
oss << s;
}
Normall, things go fine and we get os as the result of appending s into iss' content. But if iss is an totally empty istream, we will get an empty oss as well, no matter what is in s!!! Isn't it weird?
To circumvent this problem in this particular case, we switched the last two commands, so s will be added before iss' content and it will stay in oss when iss is empty. We tested it ;-)