-1

Following is my code:

#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;
}

I am getting the ISO C plus plus forbids initialization in array new error Please let me know the source of this error. thanks

4

2 回答 2

3

在 C++ 中进行统一初始化,您必须使用括号:

int *x= new int[10] {0,1,2,3,4,5,6,7,8,9};
于 2013-06-22T13:36:28.173 回答
0

在构造 x 时使用括号意味着将参数传递给数组构造函数。改用大括号为数组值提供初始化器。

于 2013-06-22T13:40:59.383 回答