How to change the size of array

Hello. I am trying to change the size of an string array but Im getting an errorI have declared string movie_name[25] as golabal variable and I am using movie_name.resize(idx) to resize but I coudnt manage to compile. Anyone can help to sort it out?
An array has a fixed size so you can't change it.
What you should use is a std::vector
https://www.cplusplus.com/reference/vector/vector/
Arrays Are Fixed Size,there is no operation to add elements to the array, One we define an array, we cannot add elements to it
I am using movie_name.resize(idx) to resize
resize(...) is a function from std::vector as @thmm mention it. Note that you need to movie_name.resize(idx + 1) if you want to use idx for accessing data of that vector.
Plain array is not an object. It has no member functions.

string movie_name[25]; has 25 distinct string objects in consecutive memory locations. The first object is at movie_name[0] and the last in movie_name[24].

The standard library has type std::array http://www.cplusplus.com/reference/array/array/
array<string,25> movie_names;
This movie_names is an object and does have some member functions, but no resize().

The std::vector is an object and can be resized.
1
2
3
4
5
6
vector<string> movie_name( 25 );
// assert: first element is movie_name[0]
// assert: last element is movie_name[24]
movie_name.resize( 42 );
// assert: first element is movie_name[0]
// assert: last element is movie_name[41] 
Topic archived. No new replies allowed.