A major concern is that STD: string is actually a structure similar to a vector <char>. It contains characters with ASCII 0.
It is not the end (otherwise there will be a problem with Unicode encoding). The actual length is obtained by length ().
There are several methods for string assignment and construction. You can refer to the document.
Example:
Char C [10] = "wer | \ t ";
C [4] = 0;
STD: String S = C;
Since C is a char * length, it can only be obtained by strlen, and strlen ends when it encounters 0, so data is lost.
To construct and assign values, the length must be passed in:
STD: String S (C, 6); // construct
S. Assign (C, 6); // value assignment, which includes the ending character 0
S. Assign (C, 5); // This does not include the end 0, for example, the serialized string of protobuf. You do not need to add 0 more.
About character encoding