gpt4 book ai didi

c++ - std::string.assign(NULL) 的行为?

转载 作者:行者123 更新时间:2023-11-30 01:20:03 28 4
gpt4 key购买 nike

有谁知道 std::string.assign(NULL) 的行为是什么?分配 NULL(使用运算符)或从 NULL 构造是未定义的。是否同样适用于此功能?

最佳答案

标准在 21.4.6.3 第 12 段中这样说:

Requires: s points to an array of at least traits::length(s) + 1 elements of charT.

在性格特征要求表62中说:

X::length(p) std::size_t yields: the smallest i such that X::eq(p[i],charT()) is true. linear

这意味着 traits::length() 将取消引用 s,因此 s 不能是指向 null 的指针。你会得到未定义的行为。

关于c++ - std::string.assign(NULL) 的行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19897484/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com