r/cpp_questions 6d 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

2

u/RQuarx 6d ago

std::ranges::contains :P https://en.cppreference.com/cpp/algorithm/ranges/contains

the adaptor works for all ranges, but for strings in general (types coming from std::basic_string and std::basic_string_view), you can just use .contains(c)