std::basic_string<CharT,Traits,Allocator>::capacity - cppreference.com
提供: cppreference.com
<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody>
|
|
(C++11未満) | |
|
|
(C++11以上) (C++20未満) |
|
|
|
(C++20以上) | |
文字列が現在確保している空間の文字数を返します。
引数
(なし)
戻り値
現在確保されている記憶域の容量。
計算量
一定。
例
#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); }
出力例:
'Exemplar' has capacity 15. 'Exemplar is an example string.' has capacity 30.