gpt4 book ai didi

C++数组评估

转载 作者:太空狗 更新时间:2023-10-29 23:41:47 25 4
gpt4 key购买 nike

有没有办法在 C++ 中“批量计算”数组的内容?例如,设 int numbers[10]={23,42,12,42,53,10,0,0,0,0}。有没有办法循环遍历数组中的每个元素,检查元素是否满足指定条件?

简而言之,我希望能够做类似的事情:

if(every element in the array meets arbitrary condition)
do this

if(array element from m to array element n==something)
do this

对于小数组,我知道我可以使用类似的东西:if(numbers[0]==blabla) && if(numbers[n]==blabla),然后这样做,但显然这不是一个现实的解决方案,当它涉及评估非常大的阵列。

最佳答案

你的意思可能是“为了”

for(int i = 0; i < size_of_array; i++)
if( the_condition_function(numbers[i])){
//do this
}

关于C++数组评估,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8033731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com