size_t max_size ( ) const;
Return maximum size of string
返回string对象所能包含的最大字符数
size_t capacity ( ) const;
Return size of allocated storage
返回string对象再不用重新分配内存的情况下所能包含的最大字符数
size_t length() const;
Return length of string
Returns a count of the number of characters in the string.
返回string对象包含的字符数
size_t size() const;
Return length of string
Returns a count of the number of characters in the string.
返回string对象包含的字符数
void clear();
Clear string
The string content is set to an empty string, erasing any previous content and thus leaving itssize at 0 characters.
将字符串清空
举例:
string testSize("Hello World");
cout<<testSize.size()<<endl;
cout<<testSize.length()<<endl;
cout<<testSize.capacity()<<endl;
cout<<testSize.max_size()<<endl;
testSize.clear();
cout<<testSize.size()<<endl;
cout<<testSize.length()<<endl;
cout<<testSize.capacity()<<endl;
cout<<testSize.max_size()<<endl;
//打印结果
11
11
11
1073741820
0
0
11
1073741820