• <i id='4XA5M'><tr id='4XA5M'><dt id='4XA5M'><q id='4XA5M'><span id='4XA5M'><b id='4XA5M'><form id='4XA5M'><ins id='4XA5M'></ins><ul id='4XA5M'></ul><sub id='4XA5M'></sub></form><legend id='4XA5M'></legend><bdo id='4XA5M'><pre id='4XA5M'><center id='4XA5M'></center></pre></bdo></b><th id='4XA5M'></th></span></q></dt></tr></i><div id='4XA5M'><tfoot id='4XA5M'></tfoot><dl id='4XA5M'><fieldset id='4XA5M'></fieldset></dl></div>
    • <bdo id='4XA5M'></bdo><ul id='4XA5M'></ul>
    <legend id='4XA5M'><style id='4XA5M'><dir id='4XA5M'><q id='4XA5M'></q></dir></style></legend>

        <small id='4XA5M'></small><noframes id='4XA5M'>

      1. <tfoot id='4XA5M'></tfoot>

        为什么 std::string 不提供到 char* 的隐式转换?

        时间:2024-05-11
        <tfoot id='8PwjZ'></tfoot>
      2. <i id='8PwjZ'><tr id='8PwjZ'><dt id='8PwjZ'><q id='8PwjZ'><span id='8PwjZ'><b id='8PwjZ'><form id='8PwjZ'><ins id='8PwjZ'></ins><ul id='8PwjZ'></ul><sub id='8PwjZ'></sub></form><legend id='8PwjZ'></legend><bdo id='8PwjZ'><pre id='8PwjZ'><center id='8PwjZ'></center></pre></bdo></b><th id='8PwjZ'></th></span></q></dt></tr></i><div id='8PwjZ'><tfoot id='8PwjZ'></tfoot><dl id='8PwjZ'><fieldset id='8PwjZ'></fieldset></dl></div>
        <legend id='8PwjZ'><style id='8PwjZ'><dir id='8PwjZ'><q id='8PwjZ'></q></dir></style></legend>
          <tbody id='8PwjZ'></tbody>

        • <small id='8PwjZ'></small><noframes id='8PwjZ'>

                <bdo id='8PwjZ'></bdo><ul id='8PwjZ'></ul>
                  本文介绍了为什么 std::string 不提供到 char* 的隐式转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  std::string 提供 const char* c_str( ) const 其中:

                  获取等效的 C 字符串

                  Get C string equivalent

                  生成一个空终止序列具有相同的字符(c 字符串)内容作为字符串对象和将其作为指向数组的指针返回字符.

                  Generates a null-terminated sequence of characters (c-string) with the same content as the string object and returns it as a pointer to an array of characters.

                  终止空字符是自动附加.

                  A terminating null character is automatically appended.

                  返回的数组指向一个具有所需的内部位置这个序列的存储空间字符加上它的终止空字符,但此中的值不应该在数组中修改计划并且只被授予留在在下一次调用 a 之前保持不变的非常量成员函数字符串对象.

                  The returned array points to an internal location with the required storage space for this sequence of characters plus its terminating null-character, but the values in this array should not be modified in the program and are only granted to remain unchanged until the next call to a non-constant member function of the string object.

                  他们为什么不直接定义operator const char*() const {return c_str();}?

                  Why don't they just define operator const char*() const {return c_str();}?

                  推荐答案

                  来自 C++ 编程语言 20.3.7(重点是我的):

                  From the C++ Programming Language 20.3.7 (emphasis mine):

                  C 样式字符串的转换可以由运算符 const char*() 而不是 c_str() 提供.这将提供隐式转换的便利但代价是在这种转换是意外的情况下.

                  Conversion to a C-style string could have been provided by an operator const char*() rather than c_str(). This would have provided the convenience of an implicit conversion at the cost of surprises in cases in which such a conversion was unexpected.

                  这篇关于为什么 std::string 不提供到 char* 的隐式转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:结束迭代器递减的便携性如何? 下一篇:numeric_limits<double>::digits10是什么意思

                  相关文章

                  <small id='CE2JD'></small><noframes id='CE2JD'>

                  <legend id='CE2JD'><style id='CE2JD'><dir id='CE2JD'><q id='CE2JD'></q></dir></style></legend>

                  • <bdo id='CE2JD'></bdo><ul id='CE2JD'></ul>

                      <tfoot id='CE2JD'></tfoot>
                      <i id='CE2JD'><tr id='CE2JD'><dt id='CE2JD'><q id='CE2JD'><span id='CE2JD'><b id='CE2JD'><form id='CE2JD'><ins id='CE2JD'></ins><ul id='CE2JD'></ul><sub id='CE2JD'></sub></form><legend id='CE2JD'></legend><bdo id='CE2JD'><pre id='CE2JD'><center id='CE2JD'></center></pre></bdo></b><th id='CE2JD'></th></span></q></dt></tr></i><div id='CE2JD'><tfoot id='CE2JD'></tfoot><dl id='CE2JD'><fieldset id='CE2JD'></fieldset></dl></div>