【发布时间】:2014-01-04 23:17:09
【问题描述】:
我试图在 C++ 中的两个函数之间发送一个包含 15 个整数的数组。第一个函数允许用户输入出租车 ID,第二个函数允许用户从数组中删除出租车 ID。但是我在函数之间发送数组时遇到问题。
void startShift ()
{
int array [15]; //array of 15 declared
for (int i = 0; i < 15; i++)
{
cout << "Please enter the taxis ID: ";
cin >> array[i]; //user enters taxi IDs
if (array[i] == 0)
break;
}
cout << "Enter 0 to return to main menu: ";
cin >> goBack;
cout << "\n";
if (goBack == 0)
update();
}
void endShift ()
{
//need the array to be sent to here
cout << "Enter 0 to return to main menu: ";
cin >> goBack;
cout << "\n";
if (goBack == 0)
update();
}
任何帮助都非常有价值。非常感谢。
【问题讨论】:
-
使用C++11和
std::array(或std::vector) -
尝试使用指向数组的指针而不是数组本身。