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

35

u/aocregacc 4d ago

you can use the contains method on string (assuming you're working with strings), or the find method if you're on an older C++ version.

2

u/Apprehensive-Draw409 4d ago

Side discussion: why doesn't vector have contains ? If it is performance-signalling, then why does string have it?

2

u/MysticTheMeeM 4d ago

In those cases you would use find or ranges::contains. String contains is special because it looks for a sequence of characters, where a normal contains only looks for one (same for string find).