【发布时间】:2017-09-03 03:06:53
【问题描述】:
所以我必须创建一个名为history[][] 的二维字符串数组,其中history[i] 存储当前参与实验i 的所有主题,history[i][j] 包含一个字符串,其中列出了所有实验这个特定的主题是其中的一部分。问题是,我必须使用int* numsubjects,一个整数数组,它告诉我有多少受试者在实验i。但是,numsubjects 的内容应该可以移动,因为受试者可以移动到其他实验中。我不知道该怎么做。我不能使用vector、dequeue 或list。
experiments = 0;
numsubjects = new int[experiments+1];
numsubjects[experiments] = n;
history = new string*[0];
for(int j = 0; j < n; j++) {
history[0] = new string[j];
history[0][j] = "0";
}
当只有一个实验,实验 0 时,上面的代码初始化所有内容。我需要一种方法来以某种方式创造历史,其中包含 numsubjects。
【问题讨论】:
-
到目前为止您尝试了什么,请显示一些代码
-
除非这是针对禁止使用标准容器的作业,否则请尝试std::vector 或std::map
标签: c++ multidimensional-array memory-management