##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::basic_string::reserve

From cppreference.com
< cpp‎ | string‎ | basic string

void reserve( size_type new_cap ); |  |

Increase the capacity of the string to a value that's greater or equal to `new_cap`. If `new_cap` is greater than the current capacity(), new storage is allocated, otherwise the method does nothing.

If `new_cap` is greater than capacity(), all iterators and references, including the past-the-end iterator, are invalidated. Otherwise, no iterators or references are invalidated.

### [edit] Parameters

new_cap | - | new capacity of the string

### [edit] Return value

(none)

### [edit] Complexity

At most linear in the size() of the string

### [edit] Notes

`reserve()` cannot be used to reduce the capacity of the container, to that end shrink_to_fit() is provided.

### [edit] See also

capacity | returns the number of characters that can be held in currently allocated storage (public member function) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/string/basic_string/reserve&oldid=64914"