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 *到char的无效转换”。
数组声明为dateAdded [20] [11],不起作用的行是这些
temp= dateAdded[count];
dateAdded[count] = dateAdded[count+1];
dateAdded[count+1] = temp;
答案 0 :(得分:1)
你说dateAdded
是一个字符数组 - 然后,由于temp
被声明为string
,所以至少以下行会失败:
dateAdded[count+1] = temp;
使用类似
的内容dateAdded[count+1] = temp[0];
将temp
声明为char
可能更好 - 没有理由使用string
临时存储char
数组的元素。