How to check if an element is contained in std::vector? C++
Hello everyone! I just started learning C++ and encountered what seems like a simple task. I have a std::vector, and I need to check if a certain number is in it. I've searched through the documentation but couldn't find a built-in method like contains() or in() as in other languages.
Here's an example of my code:
```cpp
#include
#include
int main() {
std::vector numbers = {10, 20, 30, 40, 50};
int target = 30;
// How to check if 30 is in the vector?
if (/* condition */) {
std::cout << "Found!" << std::endl;
} else {
std::cout << "Not found" << std::endl;
}
return 0;
}
```
I tried writing a loop manually, but it looks cumbersome, especially if I need to check frequently. I've heard that std::find can be used,