c++ - string类型长度的问题
ringa_lee
ringa_lee 2017-04-17 13:51:06
0
2
895
ringa_lee
ringa_lee

ringa_lee

reply all(2)
左手右手慢动作

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.

大家讲道理

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template