尝试使用max_element找出数组中的最大数字时出错 [英] Error when attempting to use max_element to figure out the highest number in an array

查看:43
本文介绍了尝试使用max_element找出数组中的最大数字时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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};

运行我的整个程序时,出现错误消息一元的无效类型参数".我查了一下,但听不懂指针"或人们指的是什么.

When running my whole program I get an error saying "invalid type argument of unary". I looked this up but was not able to understand "pointers" or what people were referring too.

推荐答案

std :: max_element()接受两个迭代器作为参数,并返回一个迭代器.在您的情况下,迭代器是指针.因此,您应该更改

std::max_element() accepts two iterators as parameters, and returns an iterator. In your case iterators are pointers. So you should change

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

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

这篇关于尝试使用max_element找出数组中的最大数字时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆