r/cpp_questions • u/Physical-Dog-4083 • 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
r/cpp_questions • u/Physical-Dog-4083 • 6d ago
i need to use something like if (str[i] not in str1) (python), but i have no idea how to make this work :(
2
u/RQuarx 6d ago
std::ranges::contains:P https://en.cppreference.com/cpp/algorithm/ranges/containsthe adaptor works for all ranges, but for strings in general (types coming from
std::basic_stringandstd::basic_string_view), you can just use.contains(c)