Hello,
I am trying to write this simple code:
std::ostringstream s;
s << 1024;
std::cout << s.str() << std::endl;
s.str(""); // <- problem
s << 512;
std::cout << s.str() << std::endl;
The problem is that behind the scene I have a limited implementation of
ostringstream on system that does not support it:
class ostringstream : public ostrstream {
public:
string str() {
char *cstr = ostrstream::str();
freeze(0);
if (cstr == 0) return string();
return string(cstr,pcount());
}
};
I have two options:
- Enhance the limited implementation, which I am not very keen on
- Find a smarter way to do str("") that works for both ostringstream and
my limited ostringstream
Any advices ?
Thanks,
Mathieu
Ps: I tried s.seekp(0) instead of str("") but that leave garbage at the
end...