string对象的size() 肯定大于等于capacity()
插入和追加insert(),append()
替换 replace()
string b("china");
59 cout << "the string china" <<" size is " << b.size() << " capacity " << b.capacity() << endl;
60 b.reserve(100);
61 cout << "the string china" <<" size is " << b.size() << " capacity " << b.capacity() << endl;
结果是
the string china size is 5 capacity 5
the string china size is 5 capacity 100
try{
64 string c("1234");
65 c.at(4);
66 }catch(exception &ex1){
67 cout << ex1.what() << endl;
68 }
其中at()会产生异常,而[]则不会产生任何异常,只是让程序猿自行决定