#include <iostream>
#include <new>
using namespace std;
int main(int argc, char const *argv[])
{
int i, n;
int *p;
cout << "How many numbers would you like to type? ";
cin>>i;
p = new (nothrow) int[i];
if (p == nullptr)
{
cout << "Error: memory could not be allocated";
} else {
for (int n = 0; n < i; n++)
{
cout << "Enter number: ";
cin>>p[n];
}
cout << "You have entered: ";
for (int n = 0; n < i; n++)
{
cout << p[n] << ", ";
}
delete[] p;
}
return 0;
}
C++基础(15)
最新推荐文章于 2024-07-20 22:49:13 发布