string str1("someString");
string str2 = string(str1);//how many copies are made here
//copy2 = copy1?
当您使用 string(otherString) 分配一个字符串时,它会复制括号中的值然后将该值复制到变量吗?
最佳答案
从技术上讲,可以有两个拷贝,但在现实生活中你只做一个拷贝。也就是说,编译器将意识到不需要临时文件并优化掉拷贝。
关于c++ - 正在制作多少 std::string 拷贝?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9948877/