简体   繁体   English

有没有办法一次操作数组的所有元素/一次操作多个变量?

[英]Is there a way to Manipulate all elements of an array at once/more than one variable at once?

Given an int array database , instead of给定一个int数组database ,而不是

if (user_input == int database[0] || user_input == int database[1])
{
    // ...
}

Could I do something more concise, like this?我可以做一些更简洁的事情吗,像这样?

if (user_input == any variable from database)
{
    // ...
}

What you probably are looking for is std::find algorithm.您可能正在寻找的是std::find算法。

Eg例如

if(std::end(database) != std::find(std::begin(database), std::end(database), user_input)) { ... }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM