String assignment to another string is by value or reference?
18:07 15 Sep 2018

I have the following code:

string line1;
string line2;

line1 = "this";
line2 = line1;
line1.replace(0, 1, "T");
cout << "line1: " << line1 << "  line2: " << line2 << endl;

The output is:

line1: This line2: this

So it looks like line1 and line2 do not point at the same string object.

This is confusing for me, as I thought that since c++ strings are mutable, changing s1 should also change s2.

c++