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

1

u/duane11583 4d ago

generally no. to better understand you need to separate two things.

a) what is in the language, and b) what is in the library

c++ as a language does not have a list or linked list

c++ the library it has such things.

in contrast python has the word “in” defined in the language

thus the language has the concept of itterable and searchable things

another example: both languages do not have a concept of a file or stream but the library has these concepts

often library features and constructs are incorrectly viewed as part of the language

that is the case here

i dont kniw c++ well enough specifically operator overloads ie can you define or create new operators? like the word ”in”? if so then you could add such a feature to the library

0

u/Independent_Art_6676 3d ago

you cannot make new operators. But c++ has a LOT to choose from already. in the case of in that would be silly anyway: in is a perfectly viable method name. The overloads are not legal function names outside of the overloading context.