连接数组,数组 1 内存消失C++

concatenating arrays, array 1 memory gone C++

本文关键字:数组 消失 C++ 内存 连接      更新时间:2023-10-16

程序由输入文件中的array1[20]和array2[40]组成。然后将 Array1 添加到 array2 的末尾(之后它们将按时间顺序排序,但我还没有到达那里,我被困在这个上面(。最终结果将被打印出来;我没有包括这部分代码,也没有包括用于输入文件的代码,以使您更容易阅读:)感谢您的帮助。

代码没有错误。输入文件上的输入均为 1 到 20,输出读取

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 135062784 135305664 134511120 135308884 6 0 6 16 135303844 134511520 134511136 134957510 135308884 135111932 135120188 0 134511156 135303952 134511168 134805750

int readSortedArray (int array[20], int count, istream& infile)
{   
count = 0;
while( (count < 20) && (infile >> array[count]) )
{
    count++;
}
return count;
}
int main ()
{
 int array[20], array1[20], array2[40];
 int count, count1, count2, x;
count1 = readSortedArray(array1, count1, infile1);
count2 = readSortedArray(array2, count2, infile2);
 for (int i=1; i < count1 + 1; i++ )
   {
       array1[i - 1] >> array2[count2 + i];
   }
 return 0;
}

似乎主函数中的 for 循环应该是这个(我应该从 0 开始(。并确保 infile2 确实包含您认为它包含的内容。

for (int i=0; i < count1; i++ )
{
  array2[count2 + i] = array1[i];
}