I wonder if i misunderstood something: does a copy constructor from std::string
not copy its content?
string str1 = "Hello World";
string str2(str1);
if(str1.c_str() == str2.c_str()) // Same pointers!
printf ("You will get into the IPC hell very soon!!");
This will print "You will get into the IPC hell very soon!!" and it annoys me.
Is this the normal behavior of std::string
? I read somewhere that it usually does a deep copy.
However, this works as expected:
string str3(str1.c_str());
if(str1.c_str() == str3.c_str()) // Different pointers!
printf ("You will get into the IPC hell very soon!!");
else
printf ("You are safe! This time!");
It copies the contents into the new string.