It requests the string to reduce its capacity to fit its size.
DeclarationFollowing is the declaration for std::string::shrink_to_fit.
void shrink_to_fit();C++11
void shrink_to_fit();Parameters
none
Return Valuenone
Exceptionsif an exception is thrown, there are no changes in the string.
ExampleIn below example for std::string::shrink_to_fit.
#include <iostream> #include <string> int main () { std::string str (500,'x'); std::cout << "1. capacity of str: " << str.capacity() << '\n'; str.resize(10); std::cout << "2. capacity of str: " << str.capacity() << '\n'; str.shrink_to_fit(); std::cout << "3. capacity of str: " << str.capacity() << '\n'; return 0; }
The sample output should be like this −
1. capacity of str: 500 2. capacity of str: 500 3. capacity of str: 10
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