It returns the size of the storage space currently allocated for the string, expressed in terms of byte.
DeclarationFollowing is the declaration for std::string::capacity.
size_t capacity() const;C++11
size_t capacity() const noexcept;Parameters
none
Return ValueIt returns the size of the storage space currently allocated for the string, expressed in terms of bytes.
Exceptionsif an exception is thrown, there are no changes in the string.
ExampleIn below example for std::string::capacity.
#include <iostream> #include <string> int main () { std::string str ("Sairamkrishna Mammahe"); std::cout << "capacity: " << str.capacity() << "\n"; return 0; }
The sample output should be like this −
capacity: 21
string.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4