string::capacity string::size string::length string::max_size

size_t capacity() const noexcept;

#include <iostream>
#include <string>

using namespace std;

int main()
{
string s1("hello");
cout << "capacity:" << s1.capacity() << endl;//15
cout << "length:" << s1.length() << endl;//5
cout << "max_size:" << s1.max_size() << endl;//9223372036854775807(63个1)
cout << "size:" << s1.size() << endl;//5
return 0;
}

posted @ 2019-12-23 13:39  MoonXu  阅读(223)  评论(0编辑  收藏  举报