我之前上 stackoverflow 查证过字符串的结尾是'0'-terminate啊, 如下引用. 但是今天查 string 的, 上面图片里的官方文档的说法又都变成了 null-terminated 了. 希望大家解答下, 谢谢
null-terminated
‘0’ terminate a string, not NULL, the NULL macro isn’t intended for use in terminating strings.----(左边包含了链接)
认证0级讲师
If it is a string of char*, the library function defaults to '
#include <string> #include <iostream> int main() { std::string s = "hello"; s[1] = 'rrreee'; std::cout << s << std::endl; return 0; }
The so-called null-terminated in null should refer to the NUL in the ASCII character set. Its encoding is the number 0, which is '
null
NUL
'
If it is a string of char*, the library function defaults to '
Output: h llo
The so-called
null-terminated
innull
should refer to theNUL
in the ASCII character set. Its encoding is the number 0, which is'