I have an array defined as;
static double Temp_data[TABLE_SIZE];
I want to change the size of the array according to the user input.
Is this possible?
Please help me.
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No. You probably want to use
std::vector<double> Temp_data;Then you can use its
resize()member function to set the size as you see fit.Edit: just to be clear, you generally want to avoid using
newdirectly if you can (and in this case, you can very easily). Direct use ofnewis a constant source of bugs of quite a few types.std::vectorhandles quite a few corner cases that are difficult to get correct withnew, ensures that the data gets cleaned up when it goes out of scope, etc.I’ve said before, and I’ll repeat here: at one time, you had little choice but to write code that used
new. Now, you do have a choice — and you should exercise it. Given a modern compiler and standard library, there’s almost never any reason to allocate an array withnew.