当我们在C中更改字符串的值时会发生什么
发布时间:2020-12-16 10:04:59 所属栏目:百科 来源:网络整理
导读:#include iostream#include stringusing namespace std;int main () { string str = "Hello"; str = "Hello World"; coutstrendl;} 字符串如何处理内存? 解决方法 回覆: ” How is the memory handled by the string? 自动的. 这意味着,除其他外,没有办法
#include <iostream> #include <string> using namespace std; int main () { string str = "Hello"; str = "Hello World"; cout<<str<<endl; } 字符串如何处理内存? 解决方法
回覆:
自动的. 这意味着,除其他外,没有办法给出一个外部创建的缓冲区std :: string.所以效率有点低.好的一面是,std :: string的交换要求(与std :: vector相对)意味着它可以使用小缓冲区优化,其中存储短字符串而不进行动态分配,这有助于提高效率. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |