+ 2
Is there an "in" like function in c++
I'm working on a project on c++ and I couldn't use "in" function in it, Is there anyone who knows?
4 odpowiedzi
+ 2
For example, in python you can do like this:
if ("h" in "hello")
Print (True)
And so on
+ 1
Mohammed Ali ,
You can use std::any_of() method.
std::string str = "hello";
bool hasCharH =
std::any_of(str.begin(), str.end(),
[](char c){return c=='h';});
if(hasCharH){
std::cout<<"Contains h";
}else{
std::cout<<"Does not contain h";
}
Make sure you #include <algorithm>.
https://devdocs.io/cpp/algorithm/all_any_none_of
0
Mohammed Ali , string does not define `in` method.
Can you describe what problem you are trying to solve? What you are expecting `in` method to do?
0
Mohammed Ali You can use
std::find() found in <algorithm>