QVector <double> data {11.0, 44.0, 22.0, 33.0, 10.0,65.0};//表示最大值: auto max = std::max_element(std::begin(data), std::end(data)); //最小值表示: auto min = std::min_element(std::begin(data), std::end(data)); //直接赋值表示 double biggest = *max; double smallest = *min; //最大值和最小值的位置的表示方式: auto positionmax = std::distance(std::begin(data),max); auto positionmin = std::distance(std::begin(data),min); int posmax = positionmax; int posmin = positionmin; qDebug()<<"biggest = "<<biggest; qDebug()<<"smallest = "<<smallest; qDebug()<<"pos ="<<posmax; qDebug()<<"posmin = "<<posmin;
这里用的QVector,std::vector应该也可以
原文地址:https://www.cnblogs.com/judes/p/12362660.html
时间: 2024-10-12 20:28:02