#include <iostream>
#include <string>
using namespace std;
int main ()
{
int size = 0;
int length = 0;
unsigned long maxsize = 0;
int capacity=0;
string str ("12345678");
string str_custom;
str_custom = str;
str_custom.resize (5);
size = str_custom.size();
length = str_custom.length();
maxsize = str_custom.max_size();
capacity = str_custom.capacity();
cout << "size = " << size << endl;
cout << "length = " << length << endl;
cout << "maxsize = " << maxsize << endl;
cout << "capacity = " << capacity << endl;
return 0;
}
程序执行结果为:
size = 8
length = 8
maxsize = 2147483647
capacity = 15
str_custom.resize (5);
修改后程序的执行结构如下:
size = 5
length = 5
maxsize = 2147483647
capacity = 15
版权说明:Copyright © 广州松河信息科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州松河信息科技有限公司 版权所有