# std::basic_string<CharT,Traits,Allocator>::capacity

< cpp‎ | string‎ | basic string

C++
 Compiler support Freestanding and hosted Language Standard library headers Named requirements Feature test macros (C++20) Language support library Concepts library (C++20) Diagnostics library General utilities library Strings library Containers library Iterators library Ranges library (C++20) Algorithms library Numerics library Localizations library Input/output library Filesystem library (C++17) Regular expressions library (C++11) Atomic operations library (C++11) Thread support library (C++11) Technical specifications Symbols index External libraries

Strings library
 Null-terminated strings Byte strings Multibyte strings Wide strings Classes basic_string basic_string_view(C++17) char_traits

std::basic_string
 Member functions basic_string::basic_string basic_string::operator= basic_string::assign basic_string::get_allocator Element access basic_string::at basic_string::operator[] basic_string::front(C++11) basic_string::back(C++11) basic_string::data basic_string::c_str Iterators Capacity basic_string::empty basic_string::sizebasic_string::length basic_string::max_size basic_string::reserve basic_string::capacity basic_string::shrink_to_fit(C++11)
 Non-member functions operator+ swap(std::basic_string) operator""s(C++14) erase(std::basic_string)erase_if(std::basic_string)(C++20)(C++20) I/O operator<> getline Comparison operator==operator!=operatoroperator<=operator>=operator<=>(until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20) Numeric conversion (C++11) Deduction guides (C++17)
Helper classes
 hashhashhashhashhash(C++11)  (C++11)(C++11)(C++11)(C++20)
 hashhashhashhashhash(C++17)(C++17)(C++17)(C++17)(C++20)

 size_type capacity() const; (until C++11) size_type capacity() const noexcept; (since C++11) (until C++20) constexpr size_type capacity() const noexcept; (since C++20)

Returns the number of characters that the string has currently allocated space for.

## Contents

(none)

### Return value

Capacity of the currently allocated storage, i.e. the storage available for storing elements.

Constant
{"ft_lang_label":"__label__en","ft_lang_prob":0.6774445,"math_prob":0.8230346,"size":1257,"snap":"2021-43-2021-49","text_gpt3_token_len":308,"char_repetition_ratio":0.1452514,"word_repetition_ratio":0.02259887,"special_character_ratio":0.27048528,"punctuation_ratio":0.1635514,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9844746,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-16T11:48:45Z\",\"WARC-Record-ID\":\"<urn:uuid:5f8d26e7-874a-4965-8f75-2f675bb0e62c>\",\"Content-Length\":\"57141\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:018be43b-648a-4e97-ab58-5e7b45008ea9>\",\"WARC-Concurrent-To\":\"<urn:uuid:75ac05b3-e24c-43be-b6bf-7e56d56afc16>\",\"WARC-IP-Address\":\"74.114.90.46\",\"WARC-Target-URI\":\"https://en.cppreference.com/w/cpp/string/basic_string/capacity\",\"WARC-Payload-Digest\":\"sha1:SGTH7VUEDI7X2ZSDEKLAWZUTP3UJUFXX\",\"WARC-Block-Digest\":\"sha1:PEG6BQJ7GNDNHWK4EUSRHPBLWW25O4US\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323584567.81_warc_CC-MAIN-20211016105157-20211016135157-00332.warc.gz\"}"}