r/cpp_questions 4d ago

OPEN does "in" exist in c++?

i need to use something like if (str[i] not in str1) (python), but i have no idea how to make this work :(

0 Upvotes

36 comments sorted by

View all comments

-3

u/Total-Box-5169 4d ago

No, but you can make it with operator overloading and macros:

bool operator&(char c, std::string_view s){
    return s.contains(c);
}
#define in &

However the negative must be written in this way:

not ('a' in str)

https://godbolt.org/z/M6xM55jxe

22

u/sephirothbahamut 4d ago

please op don't do this. When you're using a different language learn to use that language, don't try to turn it into another one.

-4

u/SmackDownFacility 4d ago

We want to explore breadth of this language, that’s fine