名前空間
変種
操作

std::basic_string::shrink_to_fit

提供: cppreference.com
< cpp‎ | string‎ | basic string

 
 
 
std::basic_string
 
void shrink_to_fit();
(C++11およびそれ以降)
未使用容量の要求が除去.
Original:
Requests the removal of unused capacity.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
それはcapacitysizeを削減するための拘束力のない要求です。要求が満たされているなら、それは実装に依存します.
Original:
It is a non-binding request to reduce capacity to size. It depends on the implementation if the request is fulfilled.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] パラメータ

(なし)

[編集] 値を返します

(なし)

[編集] 複雑性

定数

[編集]

#include <iostream>
#include <string>
int main()
{
    std::string s;
    std::cout << "Default-constructed capacity is " << s.capacity() << '\n';
    s.resize(100);
    std::cout << "Capacity of a 100-element string is " << s.capacity() << '\n';
    s.clear();
    std::cout << "Capacity after clear() is " << s.capacity() << '\n';
    s.shrink_to_fit();
    std::cout << "Capacity after shrink_to_fit() is " << s.capacity() << '\n';
}

出力:

Default-constructed capacity is 0
Capacity of a 100-element string is 100
Capacity after clear() is 100
Capacity after shrink_to_fit() is 0

[編集] 参照

文字数を返します
(パブリックメンバ関数) [edit]
現在確保されている記憶域に保持することができる文字数を返します
(パブリックメンバ関数) [edit]