How to Resize an Array of Strings in C++? Last Updated : 01 Feb, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In C++, the array of strings is useful for storing many strings in the same container. Sometimes, we need to change the size of this array. In this article, we will look at how to resize the array of strings in C++. Resize String Array in C++There is no way to directly resize the previously allocated memory. But we can create a new array, copy all the elements, and then delete the previous array using new and delete operators. C++ Programs to Resize an Array in Strings C++ // C++ Program to Resize and Copy Elements in Dynamic Array #include <iostream> using namespace std; int main() { // Create an array of strings string* oldArray = new string[5]{ "Apple", "Banana", "Cherry", "Date", "Fig" }; // Display the elements in the old array cout << "Old Array Elements:" << endl; for (int i = 0; i < 5; ++i) { cout << oldArray[i] << endl; } // Create a new array with a larger size (e.g., double // the size) int newSize = 7; string* newArray = new string[newSize]; // Copy elements from the old array to the new array for (int i = 0; i < 5; ++i) { newArray[i] = oldArray[i]; } newArray[5] = "kiwi"; newArray[6] = "dragonfruit"; // Delete the old array delete[] oldArray; // Display the elements in the new array cout << "New Array Elements:" << endl; for (int i = 0; i < newSize; ++i) { cout << newArray[i] << endl; } // Delete the new array delete[] newArray; return 0; } OutputOld Array Elements: Apple Banana Cherry Date Fig New Array Elements: Apple Banana Cherry Date Fig kiwi dragonfruit Instead of this type of array we can use dynamic std::vector of strings which by default enables dynamic resizing. Comment More infoAdvertise with us Next Article How to Resize an Array of Strings in C++? S sourabhcao9e0 Follow Improve Article Tags : C++ Programs C++ cpp-string cpp-array CPP Array and String CPP Examples +2 More Practice Tags : CPP Similar Reads How to Split a String into an Array in C++? In C++, splitting a string into an array of substrings means we have to parse the given string based on a delimiter and store each substring in an array. In this article, we will learn how to split a string into an array of substrings in C++. Example: Input: str= âHello, I am Geek from geeksforgeeks 2 min read How to Declare Pointer to an Array of Strings in C++? In C++, an array of a string is used to store multiple strings in contiguous memory locations and is commonly used when working with collections of text data. In this article, we will learn how to declare a pointer to an array of strings in C++. Pointer to Array of String in C++If we are working wit 2 min read Array of Pointers to Strings in C++ In C++, an array is a homogeneous collection of data that is stored in a contiguous memory location. We can store almost all types of data as array elements. In this article, we will learn how to store the array of pointers to strings in C++. Array of Pointers to Strings in C++A pointer to a string 6 min read How to Sort an Array of Strings Using Pointers in C++? In C++, sorting an array of strings using pointers is quite different from normal sorting because here the manipulation of pointers is done directly, and then according to which string is pointed by the pointer the sorting is done. The task is to sort a given array of strings using pointers. Example 2 min read How to Reverse a String in C++? Reversing a string means replacing the first character with the last character, second character with the second last character and so on. In this article, we will learn how to reverse a string in C++.ExamplesInput: str = "Hello World"Output: dlroW olleHExplanation: The last character is replaced by 2 min read Like