当尝试对存储在结构数组中的库存进行冒泡排序时,编译以下代码时出现两个不同的错误:
void SORT_INVENTORY(Books* list, int max, int position)
{
bool swap;
string temp;
do
{
swap = false;
for (int count = 0 ; count < (position - 1) ; count++)
{
if ( tolower(list[count].Title) > tolower(list[count + 1].Title))
{
temp = list[count];
list[count] = list[count + 1];
list[count + 1] = temp;
swap = true;
}
}
} while (swap);
我希望使用 tolower 来比较两个结构数组的 Title 元素。但是,编译器不会让我运行程序,因为它说没有匹配的函数可以调用 tolower。
当我将 if 语句切换为:
if ( ::tolower(list[count].Title) > ::tolower(list[count + 1].Title))
“无匹配函数”消息消失了,但被一个新消息取代:没有从 'string' (aka 'basic_string, allocator >') 到 'int' 的可行转换。
最后,我收到一条关于 if 语句正文中的语句的一致错误消息,指出在and中没有可行的重载 '='。temp = list[count]
list[count + 1] = temp
最后一个细节:list 是一个声明为结构数据类型的数组。我究竟做错了什么?