c++ - 又遇到了'\0' null NULL 的问题了
PHP中文网
PHP中文网 2017-04-17 15:23:44
0
2
635

我之前上 stackoverflow 查证过字符串的结尾是'0'-terminate啊, 如下引用. 但是今天查 string 的, 上面图片里的官方文档的说法又都变成了 null-terminated 了. 希望大家解答下, 谢谢

‘0’ terminate a string, not NULL, the NULL macro isn’t intended for use in terminating strings.----(左边包含了链接)

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
Peter_Zhu

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;
}

Output: h llo
小葫芦

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 '

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template