| ndawg201 (18) | |
| Could someone please tell me how exactly I'm supposed to "create an array of ints? I will be given a .txt file that I will have to read with an unknown amount of data, so I don't know exactly what size the array will be. | |
|
|
|
| firedraco (5494) | |
| You'll have to use dynamic allocation. Look up new/delete on this site for more usage information/examples. | |
|
|
|
| ndawg201 (18) | |
|
something like this? int n; int *array = new int[n]; delete []array; | |
|
|
|
| JLBorges (1754) | |||
No. Something like this:
http://www.mochima.com/tutorials/vectors.html | |||
|
|
|||
| ndawg201 (18) | |
| ok, I sort of see what you're doing now. Now on your comment for array.size(), your basically finding the size of the array right. And nothing goes between the parentheses? And then I don't know what you mean for your comment //use array. | |
|
|
|
| JLBorges (1754) | |
|
> array.size(), your basically finding the size of the array right. Yes. > And then I don't know what you mean for your comment //use array. You wouldn't have read the numbers in the file into array unless you wanted to do something with those numbers. So use the array - do whatever it is that you are supposed to do with the numbers. Read a tutorial on vectors: http://www.cprogramming.com/tutorial/stl/vector.html | |
|
|
|