gpt4 book ai didi

c++字符串使用assign函数和直接使用 '='改变值的区别

转载 作者:行者123 更新时间:2023-12-02 10:05:29 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





std::string::assign vs std::string::operator=

(2 个回答)


2年前关闭。




例如,这段代码

std::string a("this is a string");
std::string b;
b = a;
std::string c;
c.assign(a);

B和C在本质上有什么区别吗?

最佳答案

来自 cppreference

2) basic_string& assign( const basic_string& str );

...

2) Replaces the contents with a copy of str. Equivalent to *this = str;. In particular, allocator propagation may take place. (since C++11)



所以这也是一样的。

关于c++字符串使用assign函数和直接使用 '='改变值的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60375577/

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