Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does "stringstream" copy the string on which it is constructed?

In a piece of code like this one

std::string s("random;string;");
std::stringstream s_stream(s);

does s_stream make a copy of s?

I mean, what would happen if, after creating s_stream, I modified s?

like image 403
jackscorrow Avatar asked Nov 21 '25 01:11

jackscorrow


1 Answers

Yes. From http://en.cppreference.com/w/cpp/io/basic_stringstream/basic_stringstream

2) Uses a copy of str as initial contents of the underlying string device. The underlying basic_stringbuf object is constructed as basic_stringbuf<Char,Traits,Allocator>(str, mode).

like image 116
R Sahu Avatar answered Nov 22 '25 17:11

R Sahu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!