-1

I'm using stringstream in put variables in string like

int c;
stringstream ss;
string st;


ss << "some texts" << c;
st=ss.str();
cout << st;

but when i change the c and call back ss.str() again, ss.str() is saving ex-int c, not new one. Is there any functions or way to string is influenced by changing variable here?

1 Answers1

1

Stringstream doesn't bind to the variable, you have 2 options

1) Create your own class that binds to the int (saves a reference or something)

2) clear the stringstream like

ss.str(""); // clear stream

and then write to it again

ss << "some texts" << c; // set the stream again with modified c
aram
  • 1,415
  • 13
  • 27