美文网首页
c++ string c_str() 和data()区别

c++ string c_str() 和data()区别

作者: 你好667 | 来源:发表于2017-08-28 09:46 被阅读0次
    const char* c_str ( ) const;
    Get C string equivalent
    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.
    
    const char* data() const;
    Get string data
    Returns a pointer to an array of characters with the same content as the string.
    Notice that no terminating null character is appended (see member c_str for such a functionality).
    

    c_str()字符串后有'\0',而data()没有

    相关文章

      网友评论

          本文标题:c++ string c_str() 和data()区别

          本文链接:https://www.haomeiwen.com/subject/mkhudxtx.html