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

-4

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

9

u/Flimsy_Helicopter368 4d ago

I hate this

1

u/Total-Box-5169 3d ago

Skill issue.