#include#include int main() { std::vector v; v.push_back(10); v.push_back(20); v.push_back(30); std::cout << "Original Vector: "; for(auto i : v) { std::cout << i << " "; } v.resize(5); std::cout << "\nResized Vector: "; for(auto i : v) { std::cout << i << " "; } return 0; }
#includeIn this example, we are using the std::array package to create a static array. The method resize() is used to decrease the size of the array to 3. The output displays both the original array [1 2 3 4 5 6] and the resized array [1 2 3]. The package library used in both these examples is the Standard Template Library (STL).#include int main() { std::array arr{1, 2, 3, 4, 5, 6}; std::cout << "Original Array: "; for(auto i : arr) { std::cout << i << " "; } arr.resize(3); std::cout << "\nResized Array: "; for(auto i : arr) { std::cout << i << " "; } return 0; }