If function seekp does not have a valid argument is set the string in fail mode (in other words disable it). You do
ostringstream histName;
histName.seekp(0);
where, at that time, 0 is NOT valid (because it is newly created with the default constructor). Remove that line and everything works as you expect.