size()和length():返回string对象的字符个数,他们执行效果相同
max_size():返回string对象最多包含的字符数,超出会抛出异常
capacity():重新分配内存之前,string对象能包含的最大字符数
- string str("1234567");
- cout << "size=" << s.size() << endl; // size=7
- cout << "length=" << s.length() << endl; // length=7
- cout << "max_size=" << s.max_size() << endl; // max_size=4294967294
- cout << "capacity=" << s.capacity() << endl; // capacity=15