2017-09-03 80 views
1

所以我必须做出一个名为history[][],其中history[i]存储所有目前参与实验i科目,并history[i][j]包含一个字符串,列出所有的字符串2 d阵列这个特定主题已成为其中一部分的实验。问题是,我必须使用int* numsubjects,这是一个整数数组,告诉我在实验i中有多少个主题。但是,numsubjects的内容应该能够移动,因为主题可以移动到其他实验中。我不知道如何去做这件事。我不能使用vector,dequeuelist。当只有一个实验字符串动态二维数组,其中第二尺寸可以改变

 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。

+0

你到目前为止已经尝试了什么,请显示一些代码 – 3stud1ant3

+3

除非这是针对禁止使用标准容器的任务,请尝试[std :: vector](http://en.cppreference.com/w/) cpp/container/vector)或[std :: map](http://en.cppreference.com/w/cpp/container/map) – 0x5453

回答