Hi Group,
I am using gcc 3.2.2 on linux 2.4.19-4GB (SuSe 8.2).
I have a situation where I need to tie an ostringstream
to an istringstream so I can write to one and read back
what I wrote from the other. I had expected the code to
look like:
ostringstream* ostr_stdin = new ostringstream();
istringstream* istr_stdin = new istringstream();
istr_stdin->tie(ostr_stdin);
// this to test only...
// ====================
ostr_stdin->write("www", 3);
char buf[20];
buf[0] = '\0';
*istr_stdin >> buf;
cout << "read word: \"" << buf << "\"" << endl;
but that just plain and simple doesn't work! I have also
tried variants like:
istr_stdin->str(ostr_stdin->str());
or something similar with rdbuf(), which the documentation
(so far as such is available), suggests should work. With
the deprecated classes istrstream and ostrstream this was
all no problem, you simply give the same char* to the constructor.
I also tried using the i/ostringstream constructors that take
a string as argument and giving the same string, or ditto
with char*, all to no avail.
Anyone know how to do this?
many thanks,
David