Possible Duplicate:
What is the purpose of ostringstream's string constructor?
I am facing below issue. I have an ostringstream say testStr. I first insert few characters inside it using <<
testStr << somechar;
Then I modified:
testStr.Str("some string")
so that now testStr is containing "Some String"
Now I want to add some characters(say " " and "TEST") at the end so that it can become "Some String TEST".
testStr << " " << "TEST";
But I am getting " TESTString". Please let me know what can be done?
Adding sample code:
#include <iostream>
#include <sstream>
int main() {
std::ostringstream s;
s << "Hello";
s.str("WorldIsBeautiful");
s << " " << "ENDS";
std::cout << s.str() << std::endl;
}
Output is " ENDSIsBeautiful" where as I expected "WorldIsBeautiful ENDS".