这里不懂,好心的大哥哥大姐姐帮我看一下好吗?
本帖最后由 jsenxs 于 2011-06-16 22:23 编辑
复制代码
pArrayOfNumbers[0] = pLargerArray[0]
pArrayOfNumbers[1] = pLargerArray[1]
pArrayOfNumbers[2] = pLargerArray[2]
pArrayOfNumbers[3] = pLargerArray[3]
代码来自本论坛,我也有不懂的地方,拿出来问问,大家见笑啦。
- #include<iostream>
- using namespace std;
- int main()
- {
- int AllocationSize = 5;
- int *pArrayOfNumbers = new int[AllocationSize];
- int ElementsUsedSoFar = 0;
- int MaximumElementsAllowed = AllocationSize;
- int InputNumber = -1;
- cout<<endl<<"Next number = ";
- cin>>InputNumber;
-
-
- while(InputNumber > 0)
- {
- pArrayOfNumbers[ElementsUsedSoFar++] = InputNumber;
- if(ElementsUsedSoFar == MaximumElementsAllowed)
- {
- int *pLargerArray = new int[MaximumElementsAllowed+AllocationSize];//10
- for(int CopyIndex =0;CopyIndex< MaximumElementsAllowed;CopyIndex++)
- {
- pLargerArray[CopyIndex] = pArrayOfNumbers[CopyIndex];
- }
- delete [] pArrayOfNumbers;
- pArrayOfNumbers = pLargerArray; //这里 是不是将pLargerArray中的所有元素都赋值给pArrayOfNumbers,下面有一个比方,你们帮我看看对不对。
- MaximumElementsAllowed += AllocationSize;
- }
- cout<<endl<<"Next number = ";
- cin>>InputNumber;
- }
- for(int Index=0;Index<ElementsUsedSoFar;Index++)
- {
- cout<<pArrayOfNumbers[Index]<<endl;
- } system("pause");
- return 0;
- }
pArrayOfNumbers[1] = pLargerArray[1]
pArrayOfNumbers[2] = pLargerArray[2]
pArrayOfNumbers[3] = pLargerArray[3]
代码来自本论坛,我也有不懂的地方,拿出来问问,大家见笑啦。
作者: jsenxs 发布时间: 2011-06-16
看完了,然后呢?
作者: noiplee 发布时间: 2011-06-16