0
即時爲我的C++類做一個項目,我遇到了這個特定函數的問題。我不斷收到錯誤「無效的數組分配,我不知道爲什麼,我只是試圖將位置交換到一個臨時變量,並換回來以降序顯示這些信息,數組dateAdded是一個帶有字符的數組。球員Arrary作業無效
void repAge(){
cout << "You selected Listing by Age" << endl;
int i;
int pos;
string temp;
bool swap;
// Look for empty row
pos = -1;
// look for an empty book row (title[i][0] == '\0')
for (i = 0; i < 20; i++) {
if (bookTitle[i][0] == '\0') {
pos = i;
break;
}
}
// Now pos is last available value.
do
{
swap = false;
for (int count = 0; count < (pos - 1); count++)
{
if (dateAdded[count] < dateAdded[count+1])
{
temp = dateAdded[count];
dateAdded[count] = dateAdded[count+1];
dateAdded[count+1] = temp;
swap = true;
}
}
} while (swap);
for (i = 0; i< pos; i++) {
while (bookTitle[i] != '\0') {
// print it out
cout << "Title: " << bookTitle[i] << endl;
cout << "ISBN: " << isbn[i] << endl;
cout << "Quantity-On-Hand: " << qtyOnHand[i] << endl;
cout << "Wholesale Cost: " << wholesale[i] << endl;
cout << endl;
break;
}
}
彈出,確切的錯誤消息是「無效的數組分配」或「從字符*無效轉換爲char」。
陣列被聲明爲dateAdded [20] [11]和不工作的行是這些
temp= dateAdded[count];
dateAdded[count] = dateAdded[count+1];
dateAdded[count+1] = temp;
A)我們是否可以得到確切的錯誤信息,B)發生了什麼? – Borgleader
哪一行給你無效的數組賦值?你使用的所有變量的類型是什麼? – 2013-08-03 20:08:18
你的數組根本沒有聲明 –