我在C++程序中遇到了麻烦。它不断给我一个运行时错误#2 - S.它建立罚款,虽然。它建立良好。 Main应该调用另外两个函数,一个将数组插入数组,另一个函数将数组的位置反转,实质上创建一个“反向”数组。运行时检查失败#2 S C++
#include "stdafx.h"
#include <iostream>
#include <array>
using namespace std;
void storeArray(int[], int);
void flipArray(int[], int);
int main()
{
const int arraysize = 10;
int foo[arraysize]; // everyone seems to use foo so I thought I'd try it
storeArray(&foo[arraysize], arraysize);
cout << endl;
flipArray(&foo[arraysize], arraysize);
return 0;
}
void storeArray(int foo[], int arraysize)
{
int counter;
counter = 0;
while (counter < arraysize)
{
cout << "Enter number " << (counter+1) << " : ";
cin >> foo[counter]; counter++;
}
return;
}
void flipArray(int foo[], int arraysize)
{
int counter2;
int counter3;
counter2 = 0;
counter3 = 9;
for (counter2; counter2 <= 9; counter2++)
{
cout << "Value number " << (counter2 + 1) << " is " << foo[counter3] << endl;
counter3--;
}
cout << endl;
return;
}
任何帮助,将不胜感激。谢谢!
中定义的C++ STL数组,您可以使用'storeArray(foo,arraysize);'和'flipArray(foo,arraysize);'将数组末尾的地址传递给函数。 – user657267