-
Notifications
You must be signed in to change notification settings - Fork 0
/
capacity.cpp
41 lines (32 loc) · 970 Bytes
/
capacity.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// C++ Program to demonstrate the working of
// capacity(), resize() and shrink_to_fit()
#include <iostream>
#include <string> // for string class
using namespace std;
// Driver Code
int main()
{
// Initializing string
string str = "Raindrop incorporated godslayer fist";
// Displaying string
cout << "The initial string is : ";
cout << str << endl;
// Resizing string using resize()
str.resize(13);
// Displaying string
cout << "The string after resize operation is : ";
cout << str << endl;
// Displaying capacity of string
cout << "The capacity of string is : ";
cout << str.capacity() << endl;
// Displaying length of the string
cout << "The length of the string is :" << str.length()
<< endl;
// Decreasing the capacity of string
// using shrink_to_fit()
str.shrink_to_fit();
// Displaying string
cout << "The new capacity after shrinking is : ";
cout << str.capacity() << endl;
return 0;
}