What I want to do is to create string stream , and output stream, giving the buffer of string stream to output stream, so that it will output data to the string stream. Everything seems fine, but when I try to add data to buffer of the string stream it overrides the previous data. My question is why? and how can achieve a result, such that it does not override but simply adds to the string stream. Here is my code below:
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
using namespace std;
int main ()
{
stringstream s1("hello I am string stream");
streambuf *s1_bfr = s1.rdbuf();
ostream my_stream (s1_bfr);
my_stream <<"hey"<<endl;
cout <<s1.rdbuf()<<endl; //gives the result : " hey o I am string stream"( seems to me overriden)
return 0;
}