怎么区别string的capacity和size

andyzt406 andyzt406 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include <iostream>
#include <string>

using namespace std;

int main()
{
string st1("This is a test!");

cout<<st1.capacity()<<endl;
cout<<st1.size()<<endl;

return 0;
}

上面这个程序在VC6.0下得到结果是31和15,但是在linux下得到结果却是15和15,这个是什么原因产生的,是编译器的原因么,还是别的什么原因。这两个函数的区别在哪,请各位大侠帮忙
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
andyzt406
C++ 语言 65,214 成员 250,514 内容