search

Home  >  Q&A  >  body text

c++ - string类型长度的问题

ringa_leeringa_lee2809 days ago896

reply all(2)I'll reply

  • ringa_lee

    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.

    reply
    0
  • 大家讲道理

    大家讲道理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.

    reply
    0
  • Cancelreply