I can\'t understand what the \'\\0\' in the two different place mean in the following code:
string x = \"hhhdef\\n\";
cout << x << endl;
x[3]=\'\
You're representing strings in two different ways here, which is why the behaviour differs.
The second one is easier to explain; it's a C-style raw char array. In a C-style string, '\0'
denotes the null terminator; it's used to mark the end of the string. So any functions that process/display strings will stop as soon as they hit it (which is why your last string is truncated).
The first example is creating a fully-formed C++ std::string
object. These don't assign any special meaning to '\0'
(they don't have null terminators).