C++ 使用 assign 函数的字符串与直接使用 '=' 更改值的字符串之间的区别
c++ the difference between string using the assign function and directly using '=' to change the value
例如,这个代码
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( 将内容替换为str的副本。等效于
*this = str
;。特别是,可能会发生分配器传播。(自C++11起(
所以这也是一样的。
相关文章:
- C++ 使用 assign 函数的字符串与直接使用 '=' 更改值的字符串之间的区别
- 我已经建立了递归关系,它找到了两个字符串之间最长的连续公共字符串,我怎么能跳过其中一个字符串中的一个字符
- 两个字符串之间的数学运算
- 目标是找到两个 c 字符串之间的公共前缀(必须使用特定的函数标头)
- 我需要在C++的两个字符串之间找到共同的前缀
- 如何在没有映射的情况下在枚举和字符串之间进行转换?
- 正则表达式匹配字符串之间的数字
- 如何更有效地计算n个字符串之间的不匹配分数?
- 最接近的字符串:在字符串阵列中找到2个字符串之间的最小距离
- 在字符串之间插入字符
- STD :: cin和Scanf()应用于字符串之间的区别
- 使用 c++ 获取两个日期与时间字符串之间的差异(以秒为单位)
- 如何在C 中的字符串之间留出空间
- 在文本中的两个非唯一字符串之间获取子弦
- 假定相同的字符串之间的比较失败' == '比较
- C++提取两个字符串之间的数据
- C++ 和 pascal 字符串之间的区别
- 如何在C++中获取子字符串并在字符串之间添加字符
- 在C++代码中,如何让用户在2个文本字符串之间输入一个数字
- 如何在Visual C 中的BSTR和32位Unicode字符串之间进行转换