【发布时间】:2013-06-22 13:34:15
【问题描述】:
以下是我的代码:
#include<iostream.h>
#include<conio.h>
int main()
{
int *x= new int[10] (0,1,2,3,4,5,6,7,8,9);//error observed here
for(int i=0;i<9;i++)
{
cout<<x[i];
}
delete[] x;
getch();
return 0;
}
我得到 ISO C plus plus 禁止在数组新错误中初始化 请让我知道这个错误的来源。谢谢
【问题讨论】:
-
如果你知道数组的内容,用
int x[] = { 0, ... };在栈上初始化它,也可以用static... -
当您开始使用较新的编译器时,请跳过使用
new并改用std::vector,例如:std::vector<int> x{0,1,2,3,4,5,6,7,8,9};。这让您也可以跳过使用delete。
标签: c++ compiler-errors dev-c++