test Number10
test Start : IIIIIIIIIIyyyy
*** Previous operation failed
test Number10
test Start : IIIIIIIIIIyyyy
======================================================
I have following problems with the above.
Prob 1. Data which i insert after the first cout are NOT getting inserted into the stream. why the second cout is also giving the same output.(or why thrwing "*** Previous operation failed" message.)
Prob 2. I tried to clear the content of the buffer (see the commented code)
//m_testBuffer .flush(); I believe it won't clear the content of the buffer. How to clear buffer content.. and start with a fresh stream.
Prob 3. why it is showing junk values on display.
Kindly post your suggestion or solution for these problems..
Lukily, I have got an answer for the
>> Prob 1. Data which i insert after the first cout are NOT getting inserted into the stream. why the second cout is also giving the same output.(or why thrwing "*** Previous operation failed" message.)
std::cout << m_testBuffer .str() << endl;
m_testBuffer.str() function will make the stream to freeze().
We have to call m_testBuffer.freeze(false) after the first cout statement.
Prob 2 still remains.
Any one knows how to erase the contents of ostrstream ?.
your 1) and 2): ostrstream freezes the buffer once you call .str(). You have to unfreeze it after each str() by using "m_testBuffer.freeze(false);"
your 3) the .str() of ostrstream does not add any null-termination to the string. cout << std::string need the null-termination. The additional garbage is what happens to be in the memory until you accidently hit a \0 somewhere.
Why do you use ostrstream? I found stringstream always superiour (like: non of your issues occur in stringstream ;).
Ciao, Imi.
Edit: Oh, and what maikel said: Please use code - tags. It's the "<>" button. Much easier to read.. ;)
oups. I did read stringstream, and not strstream. :-)
Yep. That's why I didn't repeated your code but just summarized. I also use <sstream> and stringstream (or ostringstream), as all those "freezing/unfreezing" and incompability with std::string is just too bothersome. (strstream.str() returns char*, not std::string)