I have an assignment for a class where I need to read in values from a text file. They are just simple integers each per line.
The instructions state that I cannot use brackets [] in my code with the exception of declaring a dynamic array. For this example, we will make the size of the array 20.
(Assuming my Text file is open and working correctly)
1 2 3 4 5 6 7 8
|
int size = 20;
int* myPtr;
myPtr = new int[size]
for(int i = 0; i < size; i++)
inFile >> myPtr[i];
|
This is the only way I was able to make this work, the problem is that I am using brackets [] in the rest of the code and not when I initially declared "new int[size]"
is there another way that I can write this by not using
myPtr[i]
would it be possible to increment the address of
myPtr
another way such as
myPtr = myPtr + 1
I tried this and It did not work very well
1 2 3 4 5
|
for(int i = 0; i < size; i++)
{
inFile >> *p;
p = p + 1;
}
|
any Ideas would be helpful, thank you for your time.
**All other examples I have searched for on Google and In my textbook, use this type "myPtr[i]"