尝试使用max_element计算出数组中的最大数字时出错

时间:2014-09-21 22:04:42

标签: c++ arrays int max

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;或者人们所指的是什么。

1 个答案:

答案 0 :(得分:2)

std::max_element()接受两个迭代器作为参数,并返回一个迭代器。在你的情况下,迭代器是指针。所以你应该改变

int a = max_element(highesthuman[0], highesthuman[2]); 

int a = *max_element(highesthuman, highesthuman + 3);