C++ 动态分配数组问题

来源:百度知道 编辑:UC知道 时间:2024/05/31 18:05:26
char **handlerArray = new char*[5];
int j = 0;
int k = 0;
for (vector<string>::iterator CCII = CCstrInfo.begin();CCII < CCstrInfo.end();CCII++)
{
string tempChar = *CCII;
handlerArray[j] = new char[];
for (int k = 0;k < tempChar.length();k++)
{
handlerArray[j][k] = tempChar[k];
}
handlerArray[j][k] = '\0';
cout<<handlerArray[j]<<endl;
j++;
cout<<j<<endl;
}
这个是没错误的
char **handlerArray = new char*[5];
改成char **handlerArray = new char*[];就有错误为什么
handlerArray[j] = new char[];
他为什么可以不指定呢

c++ primer中也是说可以不指定的
char **handlerArray = new char*[5]; 5改成3以下就不报错结果也对

char **handlerArray = new char*[5];
是为指针handlerArray 分配5个元素的数组(每个元素又是个指针)

char **handlerArray = new char*[];
肯定错,既然是要求分配内存,必须指明大小啊。

这个应该与动态静态没什么关系
只要是数组,都要指定具体大小的

能不能把错误发上来,好像不是这里的问题。