// rememb-o-matic
#include <iostream>
#include <new>
using namespace std;
int main()
{
int i,n;
int * p;
cout << "How many numbers would you like to type? ";
cin >> i;
p= new (nothrow) int [i];
if (p == 0)
cout << "Error: memory could not be allocated";
else
{
for (n=0; n<i; n++)
{
cout << "Enter number: ";
cin >> p[n];
}
cout << "You have entered: ";
for (n=0; n<i; n++)
cout << p[n] << ", ";
delete[] p;
}
return 0;
}
爲什麼他們的支架裝在變量i?
p= new (nothrow) int [i];
爲什麼他們2所for
陳述又是什麼一個for
聲明做什麼呢?
爲什麼它會刪除[] p而不是變量p
?
如果你需要詢問有關循環,那麼你可能應該[在C++上閱讀一本好書](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list )。而這段代碼很糟糕。 –
也許一本介紹C++的書會是一個好的開始?在這裏有一個很好的建議清單。 –