int a = max_element(highesthuman[0], highesthuman[2]);
if( win > loss)
{
cout << "You won " << (win-loss) << " games more than the computer did! You used " << a << " the most.";
}
}
上面的数组由
给出int humanrock = 0;
int humanpaper = 0;
int humanscissors = 0;
int highesthuman [3] = {humanrock, humanpaper, humanscissors};
当我运行整个程序时,我收到一条错误,上面写着&#34;一元&#34;的无效类型参数。我看了这个但却无法理解&#34;指针&#34;或者人们所指的是什么。
答案 0 :(得分:2)
std::max_element()接受两个迭代器作为参数,并返回一个迭代器。在你的情况下,迭代器是指针。所以你应该改变
int a = max_element(highesthuman[0], highesthuman[2]);
到
int a = *max_element(highesthuman, highesthuman + 3);