我在运行时遇到崩溃错误,不知道该函数到底该怎么做或如何获取它的数据。
功能详情
编写一个接受int
数组并size
作为参数的函数,然后创建一个比给定元素大一个元素的新数组。将第一个元素设置为0
,然后将参数数组中的内容复制到新数组中。
主要细节
int n
在从输入读取的程序中使用,然后int n
从文件数据名称中读取data
并将其传递给元素移位器,然后将其打印到输出(每行一个)。
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
int element_shift(int elmts[], int size) {
int new_size = size + 1;
int shifter[new_size];
int *elmt_sft;
shifter[0] = 0;
for (int i = 1; i >= new_size; i++) {
shifter[i + 1] = elmts[i];
}
return *elmt_sft;
}
int main() {
fstream infile;
infile.open("D:\\data.txt");
int n, x;
infile >> x;
cout << "size of array: ";
cin >> n;
const int ARRAY_SIZE = n + x;
int elements[ARRAY_SIZE];
element_shift(elements, ARRAY_SIZE);
system("PAUSE");
return EXIT_SUCCESS;
}