The only way to do this with streams is to write your output to a temp buffer / file (e.g. std::stringstream
), and then copy all but the last comma to the final destination.
A better approach would be to make sure the last comma never appears in the first place.