C++中string的size,length,capacity三者到底有何区别求解
发布时间:2021-06-08
发布时间:2021-06-08
C++中string的size,length,capacity三者到底有何区别求解啦? (2013-11-22 11:23:34) #include<iostream>
#include<string>
using namespace std;
void Display(const string& str)
{
cout<<"String: "<<str<<endl;
cout<<"Size: "<<str.size()<<endl;
cout<<"Length: "<<str.length()<<endl;
cout<<"Capacity: "<<str.capacity()<<endl;
cout<<"Maxsize: "<<str.max_size()<<endl;
cout<<endl<<endl;
}
int main()
{
string s1;
Display(s1);
s1.resize(23);
Display(s1);
string s2="123456";
Display(s2);
string s3="123 456 asd";
Display(s3);
s3.resize(23);
Display(s3);
return 0;
}
上一篇:服务合作协议模板[1]