H
hpy_awad
I need to make the size of an array as variable read from screen . How can I do it ?
I need to make the size of an array as variable read from screen .
How can I do it ?
I do it ?[email protected] said:I need to make the size of an array as variable read from screen . How can
#include <vector>I need to make the size of an array as variable read from screen . How can I do it ?
John Harrison said:I do it ?[email protected] said:I need to make the size of an array as variable read from screen . How
can
Use dynamic allocation. But don't use it before you've read a book on C++.
Something like this
int main()
{
int array_size;
cin >> array_size;
int* array = new int[array_size];
...
delete[] array;
}
Attila said:First read in the size of the array from screen, into a variable with the
proper type (ptrdiff_t of stdlib.h), then create the array (with dynamic
Karthik Kumar said:Would it be more appropriate to use size_t here ?
Karthik said:Would it be more appropriate to use size_t here ?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.