-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCapacityFunction.cpp
50 lines (38 loc) · 1.27 KB
/
CapacityFunction.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
42
43
44
45
46
47
48
49
50
/**
* \file CapacityFunction.cpp
* \brief
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//--------------------------------------------------------------------------------------------------
int main(int, char **)
{
// Initializing string
std::string str = "geeksforgeeks is for geeks";
// Displaying string
std::cout << "The initial string is : ";
std::cout << str << std::endl;
// Resizing string using resize()
str.resize(13);
// Displaying string
std::cout << "The string after resize operation is : ";
std::cout << str << std::endl;
// Displaying capacity of string
std::cout << "The capacity of string is : ";
std::cout << str.capacity() << std::endl;
// Decreasing the capacity of string
// using shrink_to_fit()
str.shrink_to_fit();
// Displaying string
std::cout << "The new capacity after shrinking is : ";
std::cout << str.capacity() << std::endl;
return EXIT_SUCCESS;
}
//--------------------------------------------------------------------------------------------------
#if OUTPUT
The initial string is : geeksforgeeks is for geeks
The string after resize operation is : geeksforgeeks
The capacity of string is : 26
The new capacity after shrinking is : 15
#endif