Test found
1. std: string value (2, 'A ');
Result: value. size () = value. length () = 2; value. capacity () = 31
Std: string value (31, 'A ');
Result: value. size () = value. length () = value. capacity () = 31;
2. std: string value (32, 'A ');
Result: value. size () = value. length () = 32; value. capacity () = 63;
Std: string value (63, 'A ');
Result: value. size () = value. length () = value. capacity () = 63;
3. std: string value (80, 'A ');
Result: value. size () = value. length () = 80; value. capacity () = 95;
Std: string value (95, 'A ');
Result: value. size () = value. length () = value. capactiy () = 95;
It is not difficult to find the three examples.
A). size () and length () have the same effect, but C ++ tends to use size ();
B). string capacity, that is, capactiy (). If the value is null, capactiy () = 0;
Otherwise, the initial value of capacity () is 32, which varies according to the amount of string storage.
Initial Value = 32, step size = 32;
Author "8023"