std::basic_string<CharT,Traits,Allocator>::capacity
cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev ">
</tbody><tbody>
</tbody>
size_type capacity() const; |
( C++11) | |
size_type capacity() const noexcept; |
( C++11) ( C++20) |
|
constexpr size_type capacity() const noexcept; |
( C++20) | |
, .
()
, .. , .
.
, , - , . , std::basic_string.
#include <iomanip>
#include <iostream>
#include <string>
void show_capacity(std::string const& s)
{
std::cout << std::quoted(s) << " " << s.capacity() << ".\n";
}
int main()
{
std::string s{"Exemplar"};
show_capacity(s);
s += " .";
show_capacity(s);
s.clear();
show_capacity(s);
std::cout << "\n ."
"\n: : :\n" << std::left;
std::string g;
auto old_cap{g.capacity()};
for (int mark{}; mark != 5; ++mark)
{
while (old_cap == g.capacity())
g.push_back('.');
std::cout << std::setw( 9) << g.size()
<< std::setw(10) << g.capacity()
<< std::setw(12) << g.capacity() / static_cast<float>(old_cap) << '\n';
old_cap = g.capacity();
}
}
:
"Exemplar" 15.
"Exemplar ." 30.
"" 30.
.
: : :
16 30 2
31 60 2
61 120 2
121 240 2
241 480 2
| (public -) | |
| (public -) |