std::basic_string::c_str
来自cppreference.com
< cpp | string | basic string
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
const CharT* c_str() const; |
||
返回一个指针,指向的数据存储在字符串相当于一个null结尾的字符数组。指针的范围内
[c_str(); c_str() + size()]
是有效的,它的值对应于存储的值与一个额外的空字符在字符串中的最后一个位置后.原文:
Returns a pointer to a null-terminated character array with data equivalent to those stored in the string. The pointer is such that the range
[c_str(); c_str() + size()]
is valid and the values in it correspond to the values stored in the string with an additional null character after the last position.目录 |
[编辑] 注释
从
c_str()
可能只被视为一个指针,指向一个空结束的字符串,如果该字符串对象不包含空字符的指针.原文:
The pointer obtained from
c_str()
may only be treated as a pointer to a null-terminated character string if the string object does not contain other null characters.写入的字符数组访问
c_str()
是不确定的行为.原文:
Writing to the character array accessed through
c_str()
is undefined behavior.[编辑] 参数
(无)
[编辑] 返回值
null结尾的字符数组,这样data()[i] == operator[](i)为每
i
[0, size()]
指针。 (至 C++11)原文:
Pointer to the null-terminated character array such that data()[i] == operator[](i) for every
i
in [0, size()]
. (至 C++11)根本的特性,存储等data() + i == &operator[](i)为每
i
[0, size()]
的指针。 (C++11 起)原文:
Pointer to the underlying character storage such that data() + i == &operator[](i) for every
i
in [0, size()]
. (C++11 起)[编辑] 复杂度
恒定
[编辑] 例外
[编辑] 另请参阅
(C++11) |
访问的第一个字符 (公共成员函数) |
(C++11) |
访问的最后一个字符 (公共成员函数) |
返回一个指针,指向一个字符串的第一个字符 原文: returns a pointer to the first character of a string (公共成员函数) |