连接数组,数组 1 内存消失C++
concatenating arrays, array 1 memory gone C++
程序由输入文件中的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];
}
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- 将数组的地址分配给变量并删除
- 从C++本机插件更新Vector3数组
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 数组索引的值没有增加
- 将对象数组的引用传递给函数
- 为char数组调整zlib-zpipe
- 2D数组来自文本输入,中间有空格
- std::向量与传递值的动态数组
- 在c++中用vector填充一个简单的动态数组
- 使用strcpy将char数组的元素复制到另一个数组
- 使用指针从C++中的数组中获取最大值
- C++使用整数的压缩数组初始化对象
- 告诉一个 const char 数组,除了编译时 C 样式的字符串外,它不以 '