I am new to C++ and still juggling with stringstream. I have written a small piece of code which doesn't give required output The code is as follows:
#include "iostream"
#include "sstream"
using namespace std;
int main ()
{
string xyz;
cout << "Initial xyz : " << xyz << endl;
stringstream s1 ( xyz );
s1 << "Hello";
cout << "Final xyz : " << xyz << endl;
}
Output:
Initial xyz :
Final xyz :
My understanding is stringstream works as a wrapper around a string object.Therefore once stringstream has been initialized with a string object, any write operation on the stream will affect the underlying string object.So when I write "Hello" to stream and print the string xyz, it should display "Hello". But this clearly does not seem to be the case. Can someone please tell me where am I wrong and how can I manipulate the underlying string using stringstream? Thanks in advance ! Vimal