Hello. A bit stupid question but sorry... I haven`t got much time to slove it. So... is there ant way to check is a value in array for example: if(a in b[]) {...} something like this...? THNX C ya
Hello. A bit stupid question but sorry... I haven`t got much time to slove it. So... is there ant way to check is a value in array for example: if(a in b[]) {...} something like this...? THNX C ya
Butterfly sweep can make torando in another side of world
There is no built in functionality. You can either write a function yourself using a simple for loop or you can check <algorithm> for a searching algorithm. Maybe there is one. However, if you have just an array of ints in the magnitude of 100 to 200 numbers or less, don't waste your energy and just use a small loop.
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.
The <algorithm> header mentioned by nvoigt contains the find function that can be used with arrays as such:
Should output:Code:#include <iostream> #include <algorithm> int main() { int array[10] = { 5, 8, 10, 12, 20, 16, 13, 15, 17, 4 }; int *ptr; // Find the value 11 ptr = std::find(array,array+10,11); if( ptr != array+10 ) std::cout << "Found 11." << std::endl; else std::cout << "Could not find 11." << std::endl; // Find the value 12 ptr = std::find(array,array+10,12); if( ptr != array+10 ) std::cout << "Found 12." << std::endl; else std::cout << "Could not find 12." << std::endl; return 0; }
Code:Could not find 11. Found 12.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens