ringa_lee2017-04-17 13:53:06
So the conclusion is: string::length() or string::size() is not obtained by calling strlen(), your experiment has proven this. String does not use 0 to determine whether the string ends. String in C++ is a class, which is very different from the simple character array in C.
大家讲道理2017-04-17 13:53:06
If you initialize std::string with a c string and do not provide its length directly, the length can only be read as a legal c string. (There is a constructor that can provide the length)
Your second c string is illegal, and the length of this kind of string cannot be obtained. There is no way to check whether a c string is legal.