size_type capacity() const; |
Returns the number of characters that the string has currently allocated space for.
(none).
capacity of the currently allocated storage.
(none) | (until C++11) |
noexcept specification: noexcept | (since C++11) |
Constant.
#include <iostream> #include <string> void show_capacity(std::string const& s) { std::cout << "'" << s << "' has capacity " << s.capacity() << ".\n"; } int main() { std::string s{"Exemplar"}; show_capacity(s); s += " is an example string."; show_capacity(s); }
Possible output:
'Exemplar' has capacity 8. 'Exemplar is an example string.' has capacity 30.
returns the number of characters (public member function) |
|
reserves storage (public member function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/string/basic_string/capacity