C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C++ String reserve()This function requests a change in capacity. SyntaxConsider a string str and l is planned length of the string. Its syntax would be: str.reserve(l); Parameterl is the planned length for the string Note: capacity of the string can be greater than or equal to 'l'.Return valueIt does not return any value. ExampleLet's see the simple example. #include<iostream> using namespace std; int main() { string s="Computer Science Technology"; cout<<?Capacity is :?<<s.capacity()<<'\n'; s.reserve(33); cout<<?Now,capacity is :?<<s.capacity(); return 0; } Output: Capacity is 27 Now,capacity is : 54 In this example, we observe that how capacity of the string varies using reserve() function.
Next TopicC++ Strings
|