所以我已经阅读了其他的Stack帖子,他们都建议我使用find
。我试图这样做,但它对我不起作用。C++在数组中找到一个int
bool findInArray(int number, int array[]){
// Finds if the number is in the array
bool exists = find(begin(array), end(array), number) != end(array);
return exists;
}
但我不断收到以下错误:
error: no matching function for call to ‘begin(int*&)’
它甚至接受的答案在这里:How can I check if given int exists in array?
为什么你传递一个数组指针,而不是一个数组作为参数,以“findInArray”? – Meccano
因为在你的函数中你没有数组,所以你有一个*指针*。 –
我不知道我为什么离开那里。我一直在尝试各种各样的事情,但我错过了。我编辑了它实际上的样子。 –