问题
I know the standard specifies that it is for vectors, but what about strings?
回答1:
Yes, it is amortized constant time. See table 101 on page 716 of this document:
Table 101 lists operations that are provided for some types of sequence containers but not others. An implementation shall provide these operations for all container types shown in the “container” column, and shall implement them so as to take amortized constant time.
Operation | Description | Container
---------------+----------------------+----------------------------------
a.push_back(t) | Appends a copy of t. | basic_string, deque, list, vector
来源:https://stackoverflow.com/questions/13892989/in-c-is-the-amortized-complexity-of-stdstringpush-back-o1